- Timestamp:
- 03/10/09 11:56:00 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/freetype/FreeTypeFont3D.cpp
r7696 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 21 21 22 22 #include <osg/Geometry> 23 #include <osg/Notify> 23 #include <osg/Notify> 24 24 #include <osgDB/WriteFile> 25 25 #include <osgUtil/SmoothingVisitor> … … 27 27 28 28 29 #include <ft2build.h> 29 #include <ft2build.h> 30 30 #include FT_FREETYPE_H 31 31 … … 174 174 { 175 175 Char3DInfo* char3d = (Char3DInfo*)user; 176 char3d->cubicTo( 176 char3d->cubicTo( 177 177 osg::Vec2(FT_NUM(control1->x),FT_NUM(control1->y)), 178 178 osg::Vec2(FT_NUM(control2->x),FT_NUM(control2->y)), … … 221 221 } 222 222 223 FT_Set_Char_Size( _face, 64*64, 64*64, 600, 600); 223 FT_Set_Char_Size( _face, 64*64, 64*64, 600, 600); 224 224 225 225 int glyphIndex = FT_Get_Char_Index( _face, 'M' ); … … 291 291 // not dangling pointers remain 292 292 freeTypeLibrary->removeFont3DImplmentation(this); 293 293 294 294 // free the freetype font face itself 295 295 FT_Done_Face(_face); … … 309 309 osgText::Font3D::Glyph3D * FreeTypeFont3D::getGlyph(unsigned int charcode) 310 310 { 311 312 311 312 313 313 // 314 // GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being 315 // returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct 316 // values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect. 314 // GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being 315 // returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct 316 // values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect. 317 317 // Microsoft uses a private field for its symbol fonts 318 318 // … … 337 337 return 0; 338 338 } 339 339 340 340 // ** init FreeType to describe the glyph 341 341 Char3DInfo char3d; … … 349 349 funcs.shift = 0; 350 350 funcs.delta = 0; 351 351 352 352 // ** record description 353 353 FT_Error _error = FT_Outline_Decompose(&outline, &funcs, &char3d); … … 357 357 return 0; 358 358 } 359 359 360 360 // ** create geometry for each part of the glyph 361 361 osg::ref_ptr<osg::Geometry> frontGeo(new osg::Geometry); 362 362 frontGeo->setVertexArray(char3d.get()->getVertexArray()); 363 363 frontGeo->setPrimitiveSetList(char3d.get()->getPrimitiveSetList()); 364 364 365 365 osg::ref_ptr<osg::Geometry> wallGeo(new osg::Geometry); 366 366 wallGeo->setVertexArray(frontGeo->getVertexArray()); 367 367 368 368 osg::ref_ptr<osg::Geometry> backGeo(new osg::Geometry); 369 369 backGeo->setVertexArray(frontGeo->getVertexArray()); 370 371 372 373 // ** for conveni ance.370 371 372 373 // ** for convenience. 374 374 osg::Vec3Array * vertices = char3d._verts.get(); 375 376 377 378 // ** duplicate the vertex for the back face 375 376 377 378 // ** duplicate the vertex for the back face 379 379 // ** with a depth equal to the font depth 380 380 std::size_t len = vertices->size(); 381 381 std::size_t dlen = len * 2; 382 382 383 383 vertices->reserve(dlen); 384 384 385 385 osg::Vec3Array::iterator begin = vertices->begin(); 386 386 osg::Vec3Array::iterator it = vertices->begin(); 387 387 388 388 for (std::size_t i = 0; i != len; ++i, ++it) 389 389 vertices->push_back(*it); 390 390 // std::copy(begin, begin + len, begin + len + 1); TOCHECK 391 392 391 392 393 393 // ** and decal new vertices 394 394 unsigned int depth = _facade->getFontDepth(); … … 397 397 (*vertices)[i].z() -= depth; 398 398 } 399 399 400 400 osg::Vec3Array::iterator end; 401 401 402 402 // ** create wall and back face from the front polygon 403 // ** then accumulate them in the ap ropriate geometry wallGeo and backGeo403 // ** then accumulate them in the appropriate geometry wallGeo and backGeo 404 404 for (std::size_t i=0; i < frontGeo->getNumPrimitiveSets(); ++i) 405 405 { … … 408 408 unsigned int idx = daFront->getFirst(); 409 409 unsigned int cnt = daFront->getCount(); 410 410 411 411 // ** reverse vertices to draw the front face in the CCW 412 412 std::reverse(begin + idx, begin + idx + cnt); 413 413 414 414 // ** create the back polygon 415 415 osg::ref_ptr<osg::DrawArrays> daBack(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, idx + len, cnt)); 416 416 backGeo->addPrimitiveSet(daBack.get()); 417 418 417 418 419 419 // ** create the wall triangle strip 420 osg::ref_ptr<osg::DrawElementsUInt> deWall(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP)); 420 osg::ref_ptr<osg::DrawElementsUInt> deWall(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP)); 421 421 wallGeo->addPrimitiveSet(deWall.get()); 422 422 423 423 // ** link triangle strip 424 424 deWall->push_back(idx + len); 425 425 for (unsigned int j = 1; j < cnt; ++j) 426 { 426 { 427 427 deWall->push_back(idx + cnt - j); 428 428 deWall->push_back(idx + len + j); … … 440 440 ts.retessellatePolygons(*frontGeo); 441 441 } 442 442 443 443 { 444 444 osgUtil::Tessellator ts; … … 455 455 geode->accept(sm); 456 456 } 457 458 // ** save vertices and PrimitiveSetList of each face in the Glyph3D PrimitiveSet face list 457 458 // ** save vertices and PrimitiveSetList of each face in the Glyph3D PrimitiveSet face list 459 459 osgText::Font3D::Glyph3D * glyph3D = new osgText::Font3D::Glyph3D(charcode); 460 460 461 461 glyph3D->setVertexArray(dynamic_cast<osg::Vec3Array*>(frontGeo->getVertexArray())); 462 462 glyph3D->setNormalArray(dynamic_cast<osg::Vec3Array*>(wallGeo->getNormalArray())); 463 463 464 glyph3D->getFrontPrimitiveSetList() = frontGeo->getPrimitiveSetList(); 464 465 glyph3D->getWallPrimitiveSetList() = wallGeo->getPrimitiveSetList(); 465 466 glyph3D->getBackPrimitiveSetList() = backGeo->getPrimitiveSetList(); 466 467 467 468 468 469 FT_Glyph_Metrics* metrics = &(_face->glyph->metrics); 469 470 … … 476 477 glyph3D->setHeight((float)metrics->height / 64.0f); 477 478 478 479 479 480 FT_BBox ftbb; 480 481 FT_Outline_Get_BBox(&outline, &ftbb); … … 484 485 long ymin = ft_floor( ftbb.yMin ); 485 486 long ymax = ft_ceiling( ftbb.yMax ); 486 487 487 488 osg::BoundingBox bb(xmin / 64.0f, ymin / 64.0f, 0.0f, xmax / 64.0f, ymax / 64.0f, 0.0f); 488 489 489 490 glyph3D->setBoundingBox(bb); 490 491 491 492 return glyph3D; 492 493 } … … 501 502 FT_UInt left = FT_Get_Char_Index( _face, leftcharcode ); 502 503 FT_UInt right = FT_Get_Char_Index( _face, rightcharcode ); 503 504 // get the kerning distances. 504 505 // get the kerning distances. 505 506 FT_Vector kerning; 506 507 … … 525 526 } 526 527 527 float FreeTypeFont3D::getScale() const 528 { 529 return _scale; 530 } 528 float FreeTypeFont3D::getScale() const 529 { 530 return _scale; 531 }
