* FTFont::Advance(), FTFont::Render() and FTFont::BBox() are now far more powerful, allowing for substring display and extra spacing between characters.
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
diff --git a/demo/FTGLDemo.cpp b/demo/FTGLDemo.cpp
index 3700aff..d9303c7 100644
--- a/demo/FTGLDemo.cpp
+++ b/demo/FTGLDemo.cpp
@@ -249,7 +249,7 @@ void renderFontmetrics()
glBegin(GL_LINES);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(fonts[current_font]->Advance(myString), 0.0, 0.0);
+ glVertex3f(fonts[current_font]->Advance(myString).Xf(), 0.0, 0.0);
glVertex3f(0.0, fonts[current_font]->Ascender(), 0.0);
glVertex3f(0.0, fonts[current_font]->Descender(), 0.0);
glEnd();
@@ -404,17 +404,22 @@ void do_display (void)
glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
+ int renderMode = FTGL::RENDER_FRONT | FTGL::RENDER_BACK;
if(layouts[currentLayout])
- layouts[currentLayout]->Render(myString, FTGL::RENDER_FRONT | FTGL::RENDER_BACK);
+ layouts[currentLayout]->Render(myString, renderMode);
else
- fonts[current_font]->Render(myString, FTGL::RENDER_FRONT | FTGL::RENDER_BACK);
+ fonts[current_font]->Render(myString, -1,
+ FTPoint(), FTPoint(), renderMode);
+
if(current_font == FTGL_EXTRUDE)
{
glBindTexture(GL_TEXTURE_2D, textureID[1]);
+ renderMode = FTGL::RENDER_SIDE;
if(layouts[currentLayout])
- layouts[currentLayout]->Render(myString, FTGL::RENDER_SIDE);
+ layouts[currentLayout]->Render(myString, renderMode);
else
- fonts[current_font]->Render(myString, FTGL::RENDER_SIDE);
+ fonts[current_font]->Render(myString, -1,
+ FTPoint(), FTPoint(), renderMode);
}
glPopMatrix();
diff --git a/demo/FTGLMFontDemo.cpp b/demo/FTGLMFontDemo.cpp
index f8ceb1e..7142db9 100644
--- a/demo/FTGLMFontDemo.cpp
+++ b/demo/FTGLMFontDemo.cpp
@@ -274,7 +274,7 @@ void renderFontmetrics()
glBegin(GL_LINES);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(fonts[current_font]->Advance(myString), 0.0, 0.0);
+ glVertex3f(fonts[current_font]->Advance(myString).Xf(), 0.0, 0.0);
glVertex3f(0.0, fonts[current_font]->Ascender(), 0.0);
glVertex3f(0.0, fonts[current_font]->Descender(), 0.0);
glEnd();
diff --git a/src/FTFont/FTBitmapFont.cpp b/src/FTFont/FTBitmapFont.cpp
index c14d4f1..08df30c 100644
--- a/src/FTFont/FTBitmapFont.cpp
+++ b/src/FTFont/FTBitmapFont.cpp
@@ -63,7 +63,9 @@ FTGlyph* FTBitmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
template <typename T>
-inline void FTBitmapFontImpl::RenderI(const T *string, int renderMode)
+inline FTPoint FTBitmapFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
glPushAttrib(GL_ENABLE_BIT);
@@ -73,21 +75,28 @@ inline void FTBitmapFontImpl::RenderI(const T *string, int renderMode)
glDisable(GL_BLEND);
- FTFontImpl::Render(string, renderMode);
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
glPopAttrib();
glPopClientAttrib();
+
+ return tmp;
}
-void FTBitmapFontImpl::Render(const char* string, int renderMode)
+FTPoint FTBitmapFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
-void FTBitmapFontImpl::Render(const wchar_t* string, int renderMode)
+FTPoint FTBitmapFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
diff --git a/src/FTFont/FTBitmapFontImpl.h b/src/FTFont/FTBitmapFontImpl.h
index 1b9000a..6e2f781 100644
--- a/src/FTFont/FTBitmapFontImpl.h
+++ b/src/FTFont/FTBitmapFontImpl.h
@@ -42,14 +42,19 @@ class FTBitmapFontImpl : public FTFontImpl
size_t bufferSizeInBytes) :
FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) {};
- virtual void Render(const char* string, int renderMode);
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
- virtual void Render(const wchar_t* string, int renderMode);
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
private:
/* Internal generic Render() implementation */
template <typename T>
- inline void RenderI(const T* string, int renderMode);
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
};
#endif // __FTBitmapFontImpl__
diff --git a/src/FTFont/FTExtrudeFont.cpp b/src/FTFont/FTExtrudeFont.cpp
index 497af7e..c5cbe9a 100644
--- a/src/FTFont/FTExtrudeFont.cpp
+++ b/src/FTFont/FTExtrudeFont.cpp
@@ -44,7 +44,6 @@ FTExtrudeFont::FTExtrudeFont(char const *fontFilePath) :
FTExtrudeFont::FTExtrudeFont(const unsigned char *pBufferBytes,
size_t bufferSizeInBytes) :
FTFont(new FTExtrudeFontImpl(this, pBufferBytes, bufferSizeInBytes))
-
{}
diff --git a/src/FTFont/FTFont.cpp b/src/FTFont/FTFont.cpp
index f16a63f..b90e1a6 100644
--- a/src/FTFont/FTFont.cpp
+++ b/src/FTFont/FTFont.cpp
@@ -153,51 +153,45 @@ float FTFont::LineHeight() const
}
-void FTFont::Render(const char * string, int renderMode)
+FTPoint FTFont::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
{
- return impl->Render(string, renderMode);
+ return impl->Render(string, len, position, spacing, renderMode);
}
-void FTFont::Render(const wchar_t* string, int renderMode)
+FTPoint FTFont::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
{
- return impl->Render(string, renderMode);
+ return impl->Render(string, len, position, spacing, renderMode);
}
-float FTFont::Advance(const wchar_t* string)
+FTPoint FTFont::Advance(const char * string, const int len,
+ FTPoint position, FTPoint spacing)
{
- return impl->Advance(string);
+ return impl->Advance(string, len, position, spacing);
}
-float FTFont::Advance(const char* string)
+FTPoint FTFont::Advance(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing)
{
- return impl->Advance(string);
+ return impl->Advance(string, len, position, spacing);
}
-FTBBox FTFont::BBox(const char *string)
+FTBBox FTFont::BBox(const char *string, const int len,
+ FTPoint position, FTPoint spacing)
{
- return impl->BBox(string, 0, -1);
+ return impl->BBox(string, len, position, spacing);
}
-FTBBox FTFont::BBox(const wchar_t *string)
+FTBBox FTFont::BBox(const wchar_t *string, const int len,
+ FTPoint position, FTPoint spacing)
{
- return impl->BBox(string, 0, -1);
-}
-
-
-FTBBox FTFont::BBox(const char *string, const int start, const int end)
-{
- return impl->BBox(string, start, end);
-}
-
-
-FTBBox FTFont::BBox(const wchar_t *string, const int start, const int end)
-{
- return impl->BBox(string, start, end);
+ return impl->BBox(string, len, position, spacing);
}
@@ -250,44 +244,6 @@ FTFontImpl::~FTFontImpl()
}
-/* FIXME: DoRender should disappear, see commit [853]. */
-void FTFontImpl::DoRender(const unsigned int chr, const unsigned int nextChr,
- FTPoint &origin, int renderMode)
-{
- if(CheckGlyph(chr))
- {
- FTPoint kernAdvance = glyphList->Render(chr, nextChr, origin, renderMode);
- origin += kernAdvance;
- }
-}
-
-
-template <typename T>
-inline void FTFontImpl::RenderI(const T* string, int renderMode)
-{
- const T* c = string;
- pen = FTPoint(0., 0.);
-
- while(*c)
- {
- DoRender(*c, *(c + 1), pen, renderMode);
- ++c;
- }
-}
-
-
-void FTFontImpl::Render(const char * string, int renderMode)
-{
- RenderI((const unsigned char *)string, renderMode);
-}
-
-
-void FTFontImpl::Render(const wchar_t* string, int renderMode)
-{
- RenderI(string, renderMode);
-}
-
-
bool FTFontImpl::Attach(const char* fontFilePath)
{
if(!face.Attach(fontFilePath))
@@ -405,32 +361,32 @@ float FTFontImpl::LineHeight() const
template <typename T>
-inline FTBBox FTFontImpl::BBoxI(const T* string, const int start, const int end)
+inline FTBBox FTFontImpl::BBoxI(const T* string, const int len,
+ FTPoint position, FTPoint spacing)
{
FTBBox totalBBox;
/* Only compute the bounds if string is non-empty. */
- if(string && ('\0' != string[start]))
+ if(string && ('\0' != string[0]))
{
- float advance = 0;
-
- if(CheckGlyph(string[start]))
+ if(CheckGlyph(string[0]))
{
- totalBBox = glyphList->BBox(string[start]);
- advance = glyphList->Advance(string[start], string[start + 1]);
+ totalBBox = glyphList->BBox(string[0]);
+ position += glyphList->Advance(string[0], string[1]);
}
- /* Expand totalBox by each glyph in String (for idx) */
- for(int i = start + 1; (end < 0 && string[i])
- || (end >= 0 && i < end); i++)
+ /* Expand totalBox by each glyph in string */
+ for(int i = 1; (len < 0 && string[i]) || (len >= 0 && i < len); i++)
{
if(CheckGlyph(string[i]))
{
- FTBBox tempBBox = glyphList->BBox(string[i]);
- tempBBox += FTPoint(advance, 0.0f, 0.0f);
+ position += spacing;
+ FTBBox tempBBox = glyphList->BBox(string[i]);
+ tempBBox += position;
totalBBox |= tempBBox;
- advance += glyphList->Advance(string[i], string[i + 1]);
+
+ position += glyphList->Advance(string[i], string[i + 1]);
}
}
}
@@ -439,48 +395,105 @@ inline FTBBox FTFontImpl::BBoxI(const T* string, const int start, const int end)
}
-FTBBox FTFontImpl::BBox(const char *string, const int start, const int end)
+FTBBox FTFontImpl::BBox(const char *string, const int len,
+ FTPoint position, FTPoint spacing)
{
/* The chars need to be unsigned because they are cast to int later */
- return BBoxI((const unsigned char *)string, start, end);
+ return BBoxI((const unsigned char *)string, len, position, spacing);
}
-FTBBox FTFontImpl::BBox(const wchar_t *string, const int start, const int end)
+FTBBox FTFontImpl::BBox(const wchar_t *string, const int len,
+ FTPoint position, FTPoint spacing)
{
- return BBoxI(string, start, end);
+ return BBoxI(string, len, position, spacing);
}
template <typename T>
-inline float FTFontImpl::AdvanceI(const T* string)
+inline FTPoint FTFontImpl::AdvanceI(const T* string, const int len,
+ FTPoint position, FTPoint spacing)
{
const T* c = string;
- float width = 0.0f;
while(*c)
{
if(CheckGlyph(*c))
{
- width += glyphList->Advance(*c, *(c + 1));
+ position += glyphList->Advance(*c, *(c + 1));
}
++c;
+ if(*c)
+ {
+ position += spacing;
+ }
}
- return width;
+ return position;
}
-float FTFontImpl::Advance(const char* string)
+FTPoint FTFontImpl::Advance(const char* string, const int len,
+ FTPoint position, FTPoint spacing)
{
/* The chars need to be unsigned because they are cast to int later */
- return AdvanceI((const unsigned char *)string);
+ return AdvanceI((const unsigned char *)string,
+ len, position, spacing);
+}
+
+
+FTPoint FTFontImpl::Advance(const wchar_t* string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ return AdvanceI(string, len, position, spacing);
+}
+
+
+/* FIXME: DoRender should disappear, see commit [853]. */
+void FTFontImpl::DoRender(const unsigned int chr, const unsigned int nextChr,
+ FTPoint &origin, int renderMode)
+{
+ if(CheckGlyph(chr))
+ {
+ FTPoint kernAdvance = glyphList->Render(chr, nextChr, origin, renderMode);
+ origin += kernAdvance;
+ }
+}
+
+
+template <typename T>
+inline FTPoint FTFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ const T* c = string;
+
+ while(*c)
+ {
+ DoRender(*c, *(c + 1), position, renderMode);
+ ++c;
+ if(*c)
+ {
+ position += spacing;
+ }
+ }
+
+ return position;
+}
+
+
+FTPoint FTFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
+{
+ return RenderI((const unsigned char *)string,
+ len, position, spacing, renderMode);
}
-float FTFontImpl::Advance(const wchar_t* string)
+FTPoint FTFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
{
- return AdvanceI(string);
+ return RenderI(string, len, position, spacing, renderMode);
}
diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp
index 67f43b8..d3f8376 100644
--- a/src/FTFont/FTFontGlue.cpp
+++ b/src/FTFont/FTFontGlue.cpp
@@ -28,6 +28,7 @@
#include "FTInternals.h"
+static const FTPoint static_ftpoint;
static const FTBBox static_ftbbox;
FTGL_BEGIN_C_DECLS
@@ -222,27 +223,40 @@ C_FUN(float, ftglGetFontLineHeight, (FTGLfont *f), return 0.f, LineHeight, ());
// void FTFont::BBox(const char* string, float& llx, float& lly, float& llz,
// float& urx, float& ury, float& urz);
extern "C++" {
-C_FUN(static FTBBox, _ftglGetFontBBox, (FTGLfont *f, char const *s,
- int start, int end),
- return static_ftbbox, BBox, (s, start, end));
+C_FUN(static FTBBox, _ftglGetFontBBox, (FTGLfont *f, char const *s, int len),
+ return static_ftbbox, BBox, (s, len));
}
-void ftglGetFontBBox(FTGLfont *f, const char* s, int start, int end,
- float c[6])
+void ftglGetFontBBox(FTGLfont *f, const char* s, int len, float c[6])
{
- FTBBox ret = _ftglGetFontBBox(f, s, start, end);
+ FTBBox ret = _ftglGetFontBBox(f, s, len);
FTPoint lower = ret.Lower(), upper = ret.Upper();
c[0] = lower.Xf(); c[1] = lower.Yf(); c[2] = lower.Zf();
c[3] = upper.Xf(); c[4] = upper.Yf(); c[5] = upper.Zf();
}
// float FTFont::Advance(const char* string);
-C_FUN(float, ftglGetFontAdvance, (FTGLfont *f, const char* s),
- return 0.f, Advance, (s));
+extern "C++" {
+C_FUN(static FTPoint, _ftglGetFontAdvance, (FTGLfont *f, char const *s),
+ return static_ftpoint, Advance, (s));
+}
+
+float ftglGetFontAdvance(FTGLfont *f, const char* s)
+{
+ return _ftglGetFontAdvance(f, s).X();
+}
// virtual void Render(const char* string, int renderMode);
-C_FUN(void, ftglRenderFont, (FTGLfont *f, const char *s, int r),
- return, Render, (s, r));
+extern "C++" {
+C_FUN(static FTPoint, _ftglRenderFont, (FTGLfont *f, char const *s, int len,
+ FTPoint pos, FTPoint spacing, int mode),
+ return static_ftpoint, Render, (s, len, pos, spacing, mode));
+}
+
+void ftglRenderFont(FTGLfont *f, const char *s, int mode)
+{
+ _ftglRenderFont(f, s, -1, FTPoint(), FTPoint(), mode);
+}
// FT_Error FTFont::Error() const;
C_FUN(FT_Error, ftglGetFontError, (FTGLfont *f), return -1, Error, ());
diff --git a/src/FTFont/FTFontImpl.h b/src/FTFont/FTFontImpl.h
index 4406b7d..2c1bf6e 100644
--- a/src/FTFont/FTFontImpl.h
+++ b/src/FTFont/FTFontImpl.h
@@ -67,10 +67,6 @@ class FTFontImpl
virtual float LineHeight() const;
- virtual void Render(const char* string, int renderMode);
-
- virtual void Render(const wchar_t *string, int renderMode);
-
virtual bool FaceSize(const unsigned int size,
const unsigned int res);
@@ -82,13 +78,21 @@ class FTFontImpl
virtual void Outset(float front, float back);
- FTBBox BBox(const char *s, const int start, const int end);
+ virtual FTBBox BBox(const char *s, const int len, FTPoint, FTPoint);
+
+ virtual FTBBox BBox(const wchar_t *s, const int len, FTPoint, FTPoint);
- FTBBox BBox(const wchar_t *s, const int start, const int end);
+ virtual FTPoint Advance(const char *s, const int len,
+ FTPoint, FTPoint);
- float Advance(const wchar_t* string);
+ virtual FTPoint Advance(const wchar_t *s, const int len,
+ FTPoint, FTPoint);
- float Advance(const char* string);
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint, FTPoint, int);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint, FTPoint, int);
/**
* Current face object
@@ -154,15 +158,18 @@ class FTFontImpl
/* Internal generic BBox() implementation */
template <typename T>
- inline FTBBox BBoxI(const T *string, const int start, const int end);
+ inline FTBBox BBoxI(const T *s, const int len,
+ FTPoint position, FTPoint spacing);
- /* Internal generic BBox() implementation */
+ /* Internal generic Advance() implementation */
template <typename T>
- inline float AdvanceI(const T* string);
+ inline FTPoint AdvanceI(const T *s, const int len,
+ FTPoint position, FTPoint spacing);
/* Internal generic Render() implementation */
template <typename T>
- inline void RenderI(const T* string, int renderMode);
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
};
#endif // __FTFontImpl__
diff --git a/src/FTFont/FTOutlineFont.cpp b/src/FTFont/FTOutlineFont.cpp
index 61c1d27..8a7f270 100644
--- a/src/FTFont/FTOutlineFont.cpp
+++ b/src/FTFont/FTOutlineFont.cpp
@@ -70,7 +70,9 @@ FTGlyph* FTOutlineFont::MakeGlyph(FT_GlyphSlot ftGlyph)
template <typename T>
-inline void FTOutlineFontImpl::RenderI(const T* string, int renderMode)
+inline FTPoint FTOutlineFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
glPushAttrib(GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT
| GL_COLOR_BUFFER_BIT);
@@ -82,20 +84,27 @@ inline void FTOutlineFontImpl::RenderI(const T* string, int renderMode)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
- FTFontImpl::Render(string, renderMode);
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
glPopAttrib();
+
+ return tmp;
}
-void FTOutlineFontImpl::Render(const char* string, int renderMode)
+FTPoint FTOutlineFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
-void FTOutlineFontImpl::Render(const wchar_t* string, int renderMode)
+FTPoint FTOutlineFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
diff --git a/src/FTFont/FTOutlineFontImpl.h b/src/FTFont/FTOutlineFontImpl.h
index 8118318..8eba450 100644
--- a/src/FTFont/FTOutlineFontImpl.h
+++ b/src/FTFont/FTOutlineFontImpl.h
@@ -51,21 +51,13 @@ class FTOutlineFontImpl : public FTFontImpl
*/
virtual void Outset(float o) { outset = o; }
- /**
- * Render a string of characters
- *
- * @param string 'C' style string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const char* string, int renderMode);
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
- /**
- * Render a string of characters
- *
- * @param string wchar_t string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const wchar_t *string, int renderMode);
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
private:
/**
@@ -75,7 +67,8 @@ class FTOutlineFontImpl : public FTFontImpl
/* Internal generic Render() implementation */
template <typename T>
- inline void RenderI(const T* string, int renderMode);
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
};
#endif // __FTOutlineFontImpl__
diff --git a/src/FTFont/FTPixmapFont.cpp b/src/FTFont/FTPixmapFont.cpp
index 73438ec..f298fe5 100644
--- a/src/FTFont/FTPixmapFont.cpp
+++ b/src/FTFont/FTPixmapFont.cpp
@@ -63,7 +63,9 @@ FTGlyph* FTPixmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
template <typename T>
-inline void FTPixmapFontImpl::RenderI(const T* string, int renderMode)
+inline FTPoint FTPixmapFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
@@ -81,21 +83,28 @@ inline void FTPixmapFontImpl::RenderI(const T* string, int renderMode)
glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
- FTFontImpl::Render(string, renderMode);
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
glPopClientAttrib();
glPopAttrib();
+
+ return tmp;
}
-void FTPixmapFontImpl::Render(const char* string, int renderMode)
+FTPoint FTPixmapFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
-void FTPixmapFontImpl::Render(const wchar_t* string, int renderMode)
+FTPoint FTPixmapFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
diff --git a/src/FTFont/FTPixmapFontImpl.h b/src/FTFont/FTPixmapFontImpl.h
index e2fb24e..a622152 100644
--- a/src/FTFont/FTPixmapFontImpl.h
+++ b/src/FTFont/FTPixmapFontImpl.h
@@ -42,26 +42,19 @@ class FTPixmapFontImpl : public FTFontImpl
size_t bufferSizeInBytes) :
FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) {};
- /**
- * Render a string of characters
- *
- * @param string 'C' style string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const char* string, int renderMode);
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
- /**
- * Render a string of characters
- *
- * @param string wchar_t string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const wchar_t *string, int renderMode);
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
private:
/* Internal generic Render() implementation */
template <typename T>
- inline void RenderI(const T* string, int renderMode);
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
};
#endif // __FTPixmapFontImpl__
diff --git a/src/FTFont/FTTextureFont.cpp b/src/FTFont/FTTextureFont.cpp
index 23cdb2b..f977c0a 100644
--- a/src/FTFont/FTTextureFont.cpp
+++ b/src/FTFont/FTTextureFont.cpp
@@ -224,25 +224,31 @@ bool FTTextureFontImpl::FaceSize(const unsigned int size, const unsigned int res
template <typename T>
-inline void FTTextureFontImpl::RenderI(const T* string, int renderMode)
+inline FTPoint FTTextureFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
FTTextureGlyphImpl::ResetActiveTexture();
- FTFontImpl::Render(string, renderMode);
+ return FTFontImpl::Render(string, len, position, spacing, renderMode);
}
-void FTTextureFontImpl::Render(const char* string, int renderMode)
+FTPoint FTTextureFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
-void FTTextureFontImpl::Render(const wchar_t* string, int renderMode)
+FTPoint FTTextureFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
{
- RenderI(string, renderMode);
+ return RenderI(string, len, position, spacing, renderMode);
}
diff --git a/src/FTFont/FTTextureFontImpl.h b/src/FTFont/FTTextureFontImpl.h
index eb80408..e804f8d 100644
--- a/src/FTFont/FTTextureFontImpl.h
+++ b/src/FTFont/FTTextureFontImpl.h
@@ -54,21 +54,13 @@ class FTTextureFontImpl : public FTFontImpl
virtual bool FaceSize(const unsigned int size,
const unsigned int res = 72);
- /**
- * Render a string of characters
- *
- * @param string 'C' style string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const char* string, int renderMode);
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
- /**
- * Render a string of characters
- *
- * @param string wchar_t string to be output.
- * @param renderMode Render mode to display
- */
- virtual void Render(const wchar_t *string, int renderMode);
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
private:
/**
@@ -114,7 +106,7 @@ class FTTextureFontImpl : public FTFontImpl
/**
*An array of texture ids
*/
- FTVector<GLuint> textureIDList;
+ FTVector<GLuint> textureIDList;
/**
* The max height for glyphs in the current font
@@ -135,7 +127,7 @@ class FTTextureFontImpl : public FTFontImpl
/**
*
*/
- unsigned int numGlyphs;
+ unsigned int numGlyphs;
/**
*/
@@ -151,7 +143,8 @@ class FTTextureFontImpl : public FTFontImpl
/* Internal generic Render() implementation */
template <typename T>
- inline void RenderI(const T* string, int renderMode);
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
};
#endif // __FTTextureFontImpl__
diff --git a/src/FTGL/FTFont.h b/src/FTGL/FTFont.h
index 1d31ab7..b22ef48 100644
--- a/src/FTGL/FTFont.h
+++ b/src/FTGL/FTFont.h
@@ -215,79 +215,101 @@ class FTGL_EXPORT FTFont
* Get the bounding box for a string.
*
* @param string A char buffer.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
* @return The corresponding bounding box.
*/
- virtual FTBBox BBox(const char *string);
+ virtual FTBBox BBox(const char *string, const int len = -1,
+ FTPoint position = FTPoint(0, 0, 0),
+ FTPoint spacing = FTPoint(0, 0, 0));
/**
* Get the bounding box for a string.
*
* @param string A wchar_t buffer.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
* @return The corresponding bounding box.
*/
- virtual FTBBox BBox(const wchar_t *string);
+ virtual FTBBox BBox(const wchar_t *string, const int end = -1,
+ FTPoint position = FTPoint(0, 0, 0),
+ FTPoint spacing = FTPoint(0, 0, 0));
/**
- * Get the bounding box for a string.
+ * Get the advance for a string.
*
- * @param string A char buffer.
- * @param start The index of the first character of string
- * to check.
- * @param end The index of the last character of string to
- * check. If < 0 then characters will be parsed
- * until a '@\0' is encountered.
- * @return The corresponding bounding box.
+ * @param string 'C' style string to be checked.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The new pen position after the last character.
*/
- virtual FTBBox BBox(const char *string,
- const int start, const int end);
+ virtual FTPoint Advance(const char* string, const int end = -1,
+ FTPoint position = FTPoint(0, 0, 0),
+ FTPoint spacing = FTPoint(0, 0, 0));
/**
- * Get the bounding box for a string.
+ * Get the advance for a string.
*
- * @param string A wchar_t buffer.
- * @param start The index of the first character of string
- * to check.
- * @param end The index of the last character of string to
- * check. If < 0 then characters will be parsed
- * until a '@\0' is encountered.
- * @return The corresponding bounding box.
+ * @param string A wchar_t string
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The new pen position after the last character.
*/
- virtual FTBBox BBox(const wchar_t *string,
- const int start, const int end);
+ virtual FTPoint Advance(const wchar_t* string, const int end = -1,
+ FTPoint position = FTPoint(0, 0, 0),
+ FTPoint spacing = FTPoint(0, 0, 0));
/**
- * Get the advance width for a string.
- *
- * @param string a wchar_t string
- * @return advance width
- */
- virtual float Advance(const wchar_t* string);
-
- /**
- * Get the advance width for a string.
- *
- * @param string a char string
- * @return advance width
- */
- virtual float Advance(const char* string);
-
- /**
- * Render a string of characters
+ * Render a string of characters.
*
- * @param string 'C' style string to be output.
- * @param renderMode Render mode to display (optional)
+ * @param string 'C' style string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been displayed (optional).
+ * @param renderMode Render mode to use for display (optional).
+ * @return The new pen position after the last character was output.
*/
- virtual void Render(const char* string,
- int renderMode = FTGL::RENDER_ALL);
+ virtual FTPoint Render(const char* string, const int end = -1,
+ FTPoint position = FTPoint(0, 0, 0),
+ FTPoint spacing = FTPoint(0, 0, 0),
+ int renderMode = FTGL::RENDER_ALL);
/**
* Render a string of characters
*
* @param string wchar_t string to be output.
- * @param renderMode Render mode to display (optional)
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been displayed (optional).
+ * @param renderMode Render mode to use for display (optional).
+ * @return The new pen position after the last character was output.
*/
- virtual void Render(const wchar_t *string,
- int renderMode = FTGL::RENDER_ALL);
+ virtual FTPoint Render(const wchar_t *string, const int end = -1,
+ FTPoint position = FTPoint(0, 0),
+ FTPoint spacing = FTPoint(0, 0),
+ int renderMode = FTGL::RENDER_ALL);
/**
* Queries the Font for errors.
@@ -481,14 +503,13 @@ FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font);
*
* @param font An FTGLfont* object.
* @param string A char buffer
- * @param start The index of the first character of string to check.
- * @param end The index of the last character of string to check. If < 0
- then characters will be parsed until a '@\0' is encountered.
+ * @param len The length of the string. If < 0 then all characters will be
+ * checked until a null character is encountered (optional).
* @param bounds An array of 6 float values where the bounding box's lower
* left near and upper right far 3D coordinates will be stored.
*/
FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
- int start, int end, float bounds[6]);
+ int len, float bounds[6]);
/**
* Get the advance width for a string.
diff --git a/src/FTGlyphContainer.cpp b/src/FTGlyphContainer.cpp
index d9f7db6..b18750c 100644
--- a/src/FTGlyphContainer.cpp
+++ b/src/FTGlyphContainer.cpp
@@ -88,14 +88,13 @@ FTBBox FTGlyphContainer::BBox(const unsigned int charCode) const
}
-float FTGlyphContainer::Advance(const unsigned int charCode,
- const unsigned int nextCharCode)
+FTPoint FTGlyphContainer::Advance(const unsigned int charCode,
+ const unsigned int nextCharCode)
{
unsigned int left = charMap->FontIndex(charCode);
unsigned int right = charMap->FontIndex(nextCharCode);
- return face->KernAdvance(left, right).Xf()
- + Glyph(charCode)->Advance().Xf();
+ return face->KernAdvance(left, right) + Glyph(charCode)->Advance();
}
diff --git a/src/FTGlyphContainer.h b/src/FTGlyphContainer.h
index d27b69c..5e133d7 100644
--- a/src/FTGlyphContainer.h
+++ b/src/FTGlyphContainer.h
@@ -107,8 +107,8 @@ class FTGlyphContainer
* @param nextCharacterCode the next glyph in a string
* @return advance width
*/
- float Advance(const unsigned int characterCode,
- const unsigned int nextCharacterCode);
+ FTPoint Advance(const unsigned int characterCode,
+ const unsigned int nextCharacterCode);
/**
* Renders a character
diff --git a/src/FTLayout/FTSimpleLayout.cpp b/src/FTLayout/FTSimpleLayout.cpp
index 26a9966..1fd24f0 100644
--- a/src/FTLayout/FTSimpleLayout.cpp
+++ b/src/FTLayout/FTSimpleLayout.cpp
@@ -239,7 +239,7 @@ inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, int renderMode,
glyphBounds = GetGlyphs(currentFont)->BBox(buf[i]);
glyphWidth = glyphBounds.Upper().Xf() - glyphBounds.Lower().Xf();
- advance = GetGlyphs(currentFont)->Advance(buf[i], buf[i + 1]);
+ advance = GetGlyphs(currentFont)->Advance(buf[i], buf[i + 1]).Xf();
prevWidth = currentWidth;
// Compute the width of all glyphs up to the end of buf[i]
currentWidth = nextStart + glyphWidth;
@@ -368,7 +368,7 @@ inline void FTSimpleLayoutImpl::OutputWrappedI(const T *buf, const int start,
// the line.
if(bounds)
{
- FTBBox temp = currentFont->BBox(buf, start, end);
+ FTBBox temp = currentFont->BBox(buf + start, end - start);
// Add the extra space to the upper x dimension
temp = FTBBox(temp.Lower() + pen,
diff --git a/test/FTFont-Test.cpp b/test/FTFont-Test.cpp
index 2091f8f..ca28b1a 100644
--- a/test/FTFont-Test.cpp
+++ b/test/FTFont-Test.cpp
@@ -127,7 +127,7 @@ class FTFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, testFont->Descender(), 0.01);
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, testFont->LineHeight(), 0.01);
- float advance = testFont->Advance(GOOD_UNICODE_TEST_STRING);
+ float advance = testFont->Advance(GOOD_UNICODE_TEST_STRING).Xf();
CPPUNIT_ASSERT_EQUAL(advance, 0.f);
CPPUNIT_ASSERT(testFont->FaceSize(FONT_POINT_SIZE));
@@ -227,7 +227,7 @@ class FTFontTest : public CppUnit::TestCase
{
BadGlyphTestFont* font = new BadGlyphTestFont(GOOD_FONT_FILE);
- float advance = font->Advance(GOOD_ASCII_TEST_STRING);
+ float advance = font->Advance(GOOD_ASCII_TEST_STRING).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, advance, 0.01);
}
@@ -236,16 +236,16 @@ class FTFontTest : public CppUnit::TestCase
CPPUNIT_ASSERT(testFont->FaceSize(FONT_POINT_SIZE));
CPPUNIT_ASSERT_EQUAL(testFont->Error(), 0);
- float advance = testFont->Advance(GOOD_ASCII_TEST_STRING);
+ float advance = testFont->Advance(GOOD_ASCII_TEST_STRING).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(312.10, advance, 0.01);
- advance = testFont->Advance(BAD_ASCII_TEST_STRING);
+ advance = testFont->Advance(BAD_ASCII_TEST_STRING).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, advance, 0.01);
- advance = testFont->Advance(GOOD_UNICODE_TEST_STRING);
+ advance = testFont->Advance(GOOD_UNICODE_TEST_STRING).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(144, advance, 0.01);
- advance = testFont->Advance(BAD_UNICODE_TEST_STRING);
+ advance = testFont->Advance(BAD_UNICODE_TEST_STRING).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(0, advance, 0.01);
}
diff --git a/test/FTGlyphContainer-Test.cpp b/test/FTGlyphContainer-Test.cpp
index b840a3c..73520b7 100644
--- a/test/FTGlyphContainer-Test.cpp
+++ b/test/FTGlyphContainer-Test.cpp
@@ -86,7 +86,7 @@ class FTGlyphContainerTest : public CppUnit::TestCase
TestGlyph* glyph = new TestGlyph();
glyphContainer->Add(glyph, CHARACTER_CODE_A);
- float advance = glyphContainer->Advance(CHARACTER_CODE_A, 0);
+ float advance = glyphContainer->Advance(CHARACTER_CODE_A, 0).Xf();
CPPUNIT_ASSERT_DOUBLES_EQUAL(50, advance, 0.01);
}