Refactored BBox()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 59bedbb..84072de 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -89,78 +89,71 @@ float FTFont::Descender() const
void FTFont::BBox( const char* string,
float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
{
- llx = lly = llz = urx = ury = urz = 0.0f;
-
- if( !*string)
+ FTBBox totalBBox;
+ if( NULL != *string)
{
- return;
- }
-
- const unsigned char* c = (unsigned char*)string;
+ const unsigned char* c = (unsigned char*)string;
+ float advance = 0;
- FTBBox bbox;
-
- while( *c)
- {
CheckGlyph( *c);
- bbox = glyphList->BBox( *c);
-
- // Lower extent
- lly = lly < bbox.lowerY ? lly: bbox.lowerY;
- // Upper extent
- ury = ury > bbox.upperY ? ury: bbox.upperY;
- // Depth
- urz = urz < bbox.upperZ ? urz: bbox.upperZ;
-
- // Width
- urx += glyphList->Advance( *c, *(c + 1));
+ totalBBox = glyphList->BBox( *c);
+ advance = glyphList->Advance( *c, *(c + 1));
++c;
+
+ while( *c)
+ {
+ CheckGlyph( *c);
+ FTBBox tempBBox = glyphList->BBox( *c);
+ tempBBox.Move( FTPoint( advance, 0.0f, 0.0f));
+ totalBBox += tempBBox;
+ advance += glyphList->Advance( *c, *(c + 1));
+ ++c;
+ }
}
-
- //Final adjustments
- llx = glyphList->BBox( *string).lowerX;
- urx -= glyphList->Advance( *(c - 1), 0);
- urx += bbox.upperX;
+ llx = totalBBox.lowerX;
+ lly = totalBBox.lowerY;
+ llz = totalBBox.lowerZ;
+ urx = totalBBox.upperX;
+ ury = totalBBox.upperY;
+ urz = totalBBox.upperZ;
}
+
void FTFont::BBox( const wchar_t* string,
float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
{
- llx = lly = llz = urx = ury = urz = 0.0f;
-
- if( !*string)
- {
- return;
- }
+ FTBBox totalBBox;
- const wchar_t* c = string;
- FTBBox bbox;
-
- while( *c)
+ if( NULL != *string)
{
+ const wchar_t* c = string;
+ float advance = 0;
+
CheckGlyph( *c);
- bbox = glyphList->BBox( *c);
-
- // Lower extent
- lly = lly < bbox.lowerY ? lly: bbox.lowerY;
- // Upper extent
- ury = ury > bbox.upperY ? ury: bbox.upperY;
- // Depth
- urz = urz < bbox.upperZ ? urz: bbox.upperZ;
-
- // Width
- urx += glyphList->Advance( *c, *(c + 1));
+ totalBBox = glyphList->BBox( *c);
+ advance = glyphList->Advance( *c, *(c + 1));
++c;
+
+ while( *c)
+ {
+ CheckGlyph( *c);
+ FTBBox tempBBox = glyphList->BBox( *c);
+ tempBBox.Move( FTPoint( advance, 0.0f, 0.0f));
+ totalBBox += tempBBox;
+ advance += glyphList->Advance( *c, *(c + 1));
+ ++c;
+ }
}
-
- //Final adjustments
- llx = glyphList->BBox( *string).lowerX;
- urx -= glyphList->Advance( *(c - 1), 0);
- urx += bbox.upperX;
+ llx = totalBBox.lowerX;
+ lly = totalBBox.lowerY;
+ llz = totalBBox.lowerZ;
+ urx = totalBBox.upperX;
+ ury = totalBBox.upperY;
+ urz = totalBBox.upperZ;
}