* Remove a lot of code duplication caused by the char/wchar_t overloading thanks to templates. No API change here.
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
diff --git a/include/FTFont.h b/include/FTFont.h
index 49d7ee1..56ebf22 100644
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -193,10 +193,10 @@ class FTGL_EXPORT FTFont
/**
* Get the bounding box for a string.
*
- * @param String a char buffer
- * @param StartIdx The index of the first character of String
+ * @param string a char buffer
+ * @param start The index of the first character of string
* to check.
- * @param EndIdx The index of the last character of String to
+ * @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 llx lower left near x coord
@@ -206,16 +206,17 @@ class FTGL_EXPORT FTFont
* @param ury upper right far y coord
* @param urz upper right far z coord
*/
- void BBox(const char *String,const int StartIdx,const int EndIdx,
- float& llx, float& lly, float& llz, float& urx, float& ury, float& urz);
+ void BBox(const char *string, const int start, const int end,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz);
/**
* Get the bounding box for a string.
*
- * @param String a wchar_t buffer
- * @param StartIdx The index of the first character of String
+ * @param string a wchar_t buffer
+ * @param start The index of the first character of string
* to check.
- * @param EndIdx The index of the last character of String
+ * @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 llx lower left near x coord
@@ -225,8 +226,9 @@ class FTGL_EXPORT FTFont
* @param ury upper right far y coord
* @param urz upper right far z coord
*/
- void BBox(const wchar_t *String,const int StartIdx,const int EndIdx,
- float& llx, float& lly, float& llz, float& urx, float& ury, float& urz);
+ void BBox(const wchar_t *string, const int start, const int end,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz);
/**
* Get the bounding box for a string.
@@ -239,8 +241,11 @@ class FTGL_EXPORT FTFont
* @param ury upper right far y coord
* @param urz upper right far z coord
*/
- void BBox( const char* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
- { BBox(string,0,-1,llx,lly,llz,urx,ury,urz); }
+ void BBox(const char* string, float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
+ {
+ BBox(string, 0, -1, llx, lly, llz, urx, ury, urz);
+ }
/**
* Get the bounding box for a string.
@@ -253,8 +258,11 @@ class FTGL_EXPORT FTFont
* @param ury upper right far y coord
* @param urz upper right far z coord
*/
- void BBox( const wchar_t* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
- { BBox(string,0,-1,llx,lly,llz,urx,ury,urz); }
+ void BBox(const wchar_t* string, float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
+ {
+ BBox(string, 0, -1, llx, lly, llz, urx, ury, urz);
+ }
/**
* Get the advance width for a string.
@@ -262,7 +270,7 @@ class FTGL_EXPORT FTFont
* @param string a wchar_t string
* @return advance width
*/
- float Advance( const wchar_t* string);
+ float Advance(const wchar_t* string);
/**
* Get the advance width for a string.
@@ -270,21 +278,21 @@ class FTGL_EXPORT FTFont
* @param string a char string
* @return advance width
*/
- float Advance( const char* string);
+ float Advance(const char* string);
/**
* Render a string of characters
*
* @param string 'C' style string to be output.
*/
- virtual void Render( const char* string );
+ virtual void Render(const char* string);
/**
* Render a string of characters
*
* @param string wchar_t string to be output.
*/
- virtual void Render( const wchar_t* string );
+ virtual void Render(const wchar_t* string);
/**
* Queries the Font for errors.
@@ -292,6 +300,7 @@ class FTGL_EXPORT FTFont
* @return The current error code.
*/
FT_Error Error() const { return err;}
+
protected:
/**
* Construct a glyph of the correct type.
@@ -359,6 +368,20 @@ class FTGL_EXPORT FTFont
*/
FTPoint pen;
+ /* Internal generic BBox() implementation */
+ template <typename T>
+ inline void BBoxI(const T *string, const int start, const int end,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz);
+
+ /* Internal generic BBox() implementation */
+ template <typename T>
+ inline float AdvanceI(const T* string);
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
+
/* Allow FTLayout classes to access DoRender and CheckGlyph */
friend class FTLayout;
};
diff --git a/include/FTGLBitmapFont.h b/include/FTGLBitmapFont.h
index 34d1ba8..119f2cb 100644
--- a/include/FTGLBitmapFont.h
+++ b/include/FTGLBitmapFont.h
@@ -77,14 +77,14 @@ class FTGL_EXPORT FTGLBitmapFont : public FTFont
*
* @param string 'C' style string to be output.
*/
- void Render( const char* string);
+ void Render(const char* string);
/**
* Renders a string of characters
*
* @param string 'C' style wide string to be output.
*/
- void Render( const wchar_t* string);
+ void Render(const wchar_t* string);
// attributes
@@ -97,6 +97,9 @@ class FTGL_EXPORT FTGLBitmapFont : public FTFont
*/
inline virtual FTGlyph* MakeGlyph( unsigned int g);
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
};
#endif //__cplusplus
diff --git a/include/FTGLOutlineFont.h b/include/FTGLOutlineFont.h
index cea153e..5941fb3 100644
--- a/include/FTGLOutlineFont.h
+++ b/include/FTGLOutlineFont.h
@@ -77,14 +77,14 @@ class FTGL_EXPORT FTGLOutlineFont : public FTFont
*
* @param string 'C' style string to be output.
*/
- void Render( const char* string);
+ void Render(const char* string);
/**
* Renders a string of characters
*
* @param string wchar_t string to be output.
*/
- void Render( const wchar_t* string);
+ void Render(const wchar_t* string);
private:
/**
@@ -93,8 +93,11 @@ class FTGL_EXPORT FTGLOutlineFont : public FTFont
* @param g The glyph index NOT the char code.
* @return An FTOutlineGlyph or <code>null</code> on failure.
*/
- inline virtual FTGlyph* MakeGlyph( unsigned int g);
+ inline virtual FTGlyph* MakeGlyph(unsigned int g);
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
};
#endif //__cplusplus
diff --git a/include/FTGLPixmapFont.h b/include/FTGLPixmapFont.h
index 577000b..5394dc9 100644
--- a/include/FTGLPixmapFont.h
+++ b/include/FTGLPixmapFont.h
@@ -85,7 +85,7 @@ class FTGL_EXPORT FTGLPixmapFont : public FTFont
*
* @param string wchar_t string to be output.
*/
- void Render( const wchar_t* string);
+ void Render(const wchar_t* string);
private:
/**
@@ -94,8 +94,11 @@ class FTGL_EXPORT FTGLPixmapFont : public FTFont
* @param g The glyph index NOT the char code.
* @return An FTPixmapGlyph or <code>null</code> on failure.
*/
- inline virtual FTGlyph* MakeGlyph( unsigned int g);
+ inline virtual FTGlyph* MakeGlyph(unsigned int g);
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
};
#endif //__cplusplus
diff --git a/include/FTGLTextureFont.h b/include/FTGLTextureFont.h
index 0c4f9e2..9f95992 100644
--- a/include/FTGLTextureFont.h
+++ b/include/FTGLTextureFont.h
@@ -87,14 +87,14 @@ class FTGL_EXPORT FTGLTextureFont : public FTFont
*
* @param string 'C' style string to be output.
*/
- virtual void Render( const char* string);
+ virtual void Render(const char* string);
/**
* Renders a string of characters
*
* @param string wchar_t string to be output.
*/
- virtual void Render( const wchar_t* string);
+ virtual void Render(const wchar_t* string);
private:
@@ -179,6 +179,9 @@ class FTGL_EXPORT FTGLTextureFont : public FTFont
*/
int yOffset;
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
};
#endif //__cplusplus
diff --git a/include/FTSimpleLayout.h b/include/FTSimpleLayout.h
index 86ce175..921cdf1 100644
--- a/include/FTSimpleLayout.h
+++ b/include/FTSimpleLayout.h
@@ -302,6 +302,29 @@ class FTGL_EXPORT FTSimpleLayout : public FTLayout
* a percentage of the font's line height.
*/
float lineSpacing;
+
+ /* Internal generic BBox() implementation */
+ template <typename T>
+ inline void BBoxI(const T* string, float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz);
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string);
+
+ /* Internal generic RenderSpace() implementation */
+ template <typename T>
+ inline void RenderSpaceI(const T* string, const int start,
+ const int end, const float ExtraSpace = 0.0);
+
+ /* Internal generic WrapText() implementation */
+ template <typename T>
+ void WrapTextI(const T* buf, FTBBox *bounds = NULL);
+
+ /* Internal generic OutputWrapped() implementation */
+ template <typename T>
+ void OutputWrappedI(const T* buf, const int start, const int end,
+ const float RemainingWidth, FTBBox *bounds);
};
#endif /* __FTSimpleLayout__ */
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 974d8c2..671d064 100644
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -163,14 +163,17 @@ float FTFont::Descender() const
return charSize.Descender();
}
+
float FTFont::LineHeight() const
{
return charSize.Height();
}
-void FTFont::BBox(const char* string, const int start, const int end,
- float& llx, float& lly, float& llz,
- float& urx, float& ury, float& urz)
+
+template <typename T>
+inline void FTFont::BBoxI(const T* string, const int start, const int end,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
{
FTBBox totalBBox;
@@ -210,58 +213,33 @@ void FTFont::BBox(const char* string, const int start, const int end,
}
-void FTFont::BBox(const wchar_t* string, const int start, const int end,
+void FTFont::BBox(const char* string, const int start, const int end,
float& llx, float& lly, float& llz,
float& urx, float& ury, float& urz)
{
- FTBBox totalBBox;
-
- /* Only compute the bounds if string is non-empty. */
- if(string && ('\0' != string[start]))
- {
- float advance = 0;
-
- if(CheckGlyph(string[start]))
- {
- totalBBox = glyphList->BBox(string[start]);
- advance = glyphList->Advance(string[start], string[start + 1]);
- }
+ return BBoxI(string, start, end, llx, lly, llz, urx, ury, urz);
+}
- /* Expand totalBox by each glyph in String (for idx) */
- for(int i = start + 1; (end < 0 && string[i])
- || (end >= 0 && i < end); i++)
- {
- if(CheckGlyph(string[i]))
- {
- FTBBox tempBBox = glyphList->BBox(string[i]);
- tempBBox.Move(FTPoint(advance, 0.0f, 0.0f));
- totalBBox += tempBBox;
- advance += glyphList->Advance(string[i], string[i + 1]);
- }
- }
- }
-
- // TODO: The Z values do not follow the proper ordering. I'm not sure why.
- llx = totalBBox.lowerX < totalBBox.upperX ? totalBBox.lowerX : totalBBox.upperX;
- lly = totalBBox.lowerY < totalBBox.upperY ? totalBBox.lowerY : totalBBox.upperY;
- llz = totalBBox.lowerZ < totalBBox.upperZ ? totalBBox.lowerZ : totalBBox.upperZ;
- urx = totalBBox.lowerX > totalBBox.upperX ? totalBBox.lowerX : totalBBox.upperX;
- ury = totalBBox.lowerY > totalBBox.upperY ? totalBBox.lowerY : totalBBox.upperY;
- urz = totalBBox.lowerZ > totalBBox.upperZ ? totalBBox.lowerZ : totalBBox.upperZ;
+void FTFont::BBox(const wchar_t* string, const int start, const int end,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
+{
+ return BBoxI(string, start, end, llx, lly, llz, urx, ury, urz);
}
-float FTFont::Advance( const wchar_t* string)
+template <typename T>
+inline float FTFont::AdvanceI(const T* string)
{
- const wchar_t* c = string;
+ const T* c = string;
float width = 0.0f;
- while( *c)
+ while(*c)
{
- if(CheckGlyph( *c))
+ if(CheckGlyph(*c))
{
- width += glyphList->Advance( *c, *(c + 1));
+ width += glyphList->Advance(*c, *(c + 1));
}
++c;
}
@@ -270,21 +248,15 @@ float FTFont::Advance( const wchar_t* string)
}
-float FTFont::Advance( const char* string)
+float FTFont::Advance(const wchar_t* string)
{
- const unsigned char* c = (unsigned char*)string;
- float width = 0.0f;
+ return AdvanceI(string);
+}
- while( *c)
- {
- if(CheckGlyph( *c))
- {
- width += glyphList->Advance( *c, *(c + 1));
- }
- ++c;
- }
-
- return width;
+
+float FTFont::Advance(const char* string)
+{
+ return AdvanceI((const unsigned char *)string);
}
@@ -300,35 +272,32 @@ void FTFont::DoRender(const unsigned int chr,
}
-void FTFont::Render( const char* string )
+template <typename T>
+inline void FTFont::RenderI(const T* string)
{
- const unsigned char* c = (unsigned char*)string;
+ const T* c = string;
pen.X(0); pen.Y(0);
- while( *c)
+ while(*c)
{
- if(CheckGlyph( *c))
+ if(CheckGlyph(*c))
{
- pen = glyphList->Render( *c, *(c + 1), pen);
+ pen = glyphList->Render(*c, *(c + 1), pen);
}
++c;
}
}
-void FTFont::Render( const wchar_t* string )
+void FTFont::Render(const wchar_t* string)
{
- const wchar_t* c = string;
- pen.X(0); pen.Y(0);
+ RenderI(string);
+}
- while( *c)
- {
- if(CheckGlyph( *c))
- {
- pen = glyphList->Render( *c, *(c + 1), pen);
- }
- ++c;
- }
+
+void FTFont::Render(const char * string)
+{
+ RenderI((const unsigned char *)string);
}
diff --git a/src/FTGLBitmapFont.cpp b/src/FTGLBitmapFont.cpp
index 5ec1c7a..e3a2199 100644
--- a/src/FTGLBitmapFont.cpp
+++ b/src/FTGLBitmapFont.cpp
@@ -69,8 +69,9 @@ FTGlyph* FTGLBitmapFont::MakeGlyph( unsigned int g)
}
-void FTGLBitmapFont::Render( const char* string)
-{
+template <typename T>
+inline void FTGLBitmapFont::RenderI(const T *string)
+{
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
glPushAttrib( GL_ENABLE_BIT);
@@ -86,20 +87,15 @@ void FTGLBitmapFont::Render( const char* string)
}
-void FTGLBitmapFont::Render( const wchar_t* string)
+void FTGLBitmapFont::Render(const char* string)
{
- glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
- glPushAttrib( GL_ENABLE_BIT);
-
- glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
-
- glDisable( GL_BLEND);
+ RenderI(string);
+}
- FTFont::Render( string);
- glPopAttrib();
- glPopClientAttrib();
+void FTGLBitmapFont::Render(const wchar_t* string)
+{
+ RenderI(string);
}
diff --git a/src/FTGLOutlineFont.cpp b/src/FTGLOutlineFont.cpp
index cd78435..b7dbc1d 100644
--- a/src/FTGLOutlineFont.cpp
+++ b/src/FTGLOutlineFont.cpp
@@ -69,37 +69,34 @@ FTGlyph* FTGLOutlineFont::MakeGlyph( unsigned int g)
}
-void FTGLOutlineFont::Render( const char* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT);
-
- glDisable( GL_TEXTURE_2D);
-
- glEnable( GL_LINE_SMOOTH);
- glHint( GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
+template <typename T>
+inline void FTGLOutlineFont::RenderI(const T* string)
+{
+ glPushAttrib(GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT
+ | GL_COLOR_BUFFER_BIT);
+
+ glDisable(GL_TEXTURE_2D);
+
+ glEnable(GL_LINE_SMOOTH);
+ glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
- FTFont::Render( string);
+ FTFont::Render(string);
glPopAttrib();
}
-void FTGLOutlineFont::Render( const wchar_t* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT);
-
- glDisable( GL_TEXTURE_2D);
-
- glEnable( GL_LINE_SMOOTH);
- glHint( GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
- glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+void FTGLOutlineFont::Render(const char* string)
+{
+ RenderI(string);
+}
- FTFont::Render( string);
- glPopAttrib();
+void FTGLOutlineFont::Render(const wchar_t* string)
+{
+ RenderI(string);
}
diff --git a/src/FTGLPixmapFont.cpp b/src/FTGLPixmapFont.cpp
index 71253ae..a50fb15 100644
--- a/src/FTGLPixmapFont.cpp
+++ b/src/FTGLPixmapFont.cpp
@@ -69,53 +69,41 @@ FTGlyph* FTGLPixmapFont::MakeGlyph( unsigned int g)
}
-void FTGLPixmapFont::Render( const char* string)
+template <typename T>
+inline void FTGLPixmapFont::RenderI(const T* string)
{
- glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
- glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
+ glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
+ glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable( GL_TEXTURE_2D);
+ glDisable(GL_TEXTURE_2D);
GLfloat ftglColour[4];
- glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour);
+ glGetFloatv(GL_CURRENT_RASTER_COLOR, ftglColour);
glPixelTransferf(GL_RED_SCALE, ftglColour[0]);
glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]);
glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
- FTFont::Render( string);
+ FTFont::Render(string);
glPopClientAttrib();
glPopAttrib();
}
-void FTGLPixmapFont::Render( const wchar_t* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
- glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
-
- glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glDisable( GL_TEXTURE_2D);
-
- GLfloat ftglColour[4];
- glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour);
-
- glPixelTransferf(GL_RED_SCALE, ftglColour[0]);
- glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]);
- glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
- glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
+void FTGLPixmapFont::Render(const char* string)
+{
+ RenderI(string);
+}
- FTFont::Render( string);
- glPopClientAttrib();
- glPopAttrib();
+void FTGLPixmapFont::Render(const wchar_t* string)
+{
+ RenderI(string);
}
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index de967f0..8bdcb55 100644
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -189,33 +189,31 @@ bool FTGLTextureFont::FaceSize( const unsigned int size, const unsigned int res)
}
-void FTGLTextureFont::Render( const char* string)
+template <typename T>
+inline void FTGLTextureFont::RenderI(const T* string)
{
- glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
+ glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
FTTextureGlyph::ResetActiveTexture();
- FTFont::Render( string);
+ FTFont::Render(string);
glPopAttrib();
}
-void FTGLTextureFont::Render( const wchar_t* string)
-{
- glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
-
- glEnable(GL_BLEND);
- glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
-
- FTTextureGlyph::ResetActiveTexture();
-
- FTFont::Render( string);
-
- glPopAttrib();
+void FTGLTextureFont::Render(const char* string)
+{
+ RenderI(string);
+}
+
+
+void FTGLTextureFont::Render(const wchar_t* string)
+{
+ RenderI(string);
}
diff --git a/src/FTSimpleLayout.cpp b/src/FTSimpleLayout.cpp
index fa1f51d..2a27035 100644
--- a/src/FTSimpleLayout.cpp
+++ b/src/FTSimpleLayout.cpp
@@ -52,8 +52,10 @@ FTSimpleLayout::FTSimpleLayout()
}
-void FTSimpleLayout::BBox(const char *string, float& llx, float& lly,
- float& llz, float& urx, float& ury, float& urz)
+template <typename T>
+inline void FTSimpleLayout::BBoxI(const T* string,
+ float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
{
FTBBox bounds;
@@ -63,18 +65,22 @@ void FTSimpleLayout::BBox(const char *string, float& llx, float& lly,
}
-void FTSimpleLayout::BBox(const wchar_t *string, float& llx, float& lly,
+void FTSimpleLayout::BBox(const char *string, float& llx, float& lly,
float& llz, float& urx, float& ury, float& urz)
{
- FTBBox bounds;
+ BBoxI(string, llx, lly, llz, urx, ury, urz);
+}
- WrapText(string, &bounds);
- llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
- urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
+
+void FTSimpleLayout::BBox(const wchar_t *string, float& llx, float& lly,
+ float& llz, float& urx, float& ury, float& urz)
+{
+ BBoxI(string, llx, lly, llz, urx, ury, urz);
}
-void FTSimpleLayout::Render(const char *string)
+template <typename T>
+inline void FTSimpleLayout::RenderI(const T *string)
{
pen.X(0.0f);
pen.Y(0.0f);
@@ -82,15 +88,20 @@ void FTSimpleLayout::Render(const char *string)
}
+void FTSimpleLayout::Render(const char *string)
+{
+ RenderI(string);
+}
+
+
void FTSimpleLayout::Render(const wchar_t* string)
{
- pen.X(0.0f);
- pen.Y(0.0f);
- WrapText(string, NULL);
+ RenderI(string);
}
-void FTSimpleLayout::WrapText(const char *buf, FTBBox *bounds)
+template <typename T>
+inline void FTSimpleLayout::WrapTextI(const T *buf, FTBBox *bounds)
{
int breakIdx = 0; // index of the last break character
int lineStart = 0; // character index of the line start
@@ -205,124 +216,23 @@ void FTSimpleLayout::WrapText(const char *buf, FTBBox *bounds)
}
-void FTSimpleLayout::WrapText(const wchar_t* buf, FTBBox *bounds)
+void FTSimpleLayout::WrapText(const char *buf, FTBBox *bounds)
{
- int breakIdx = 0; // index of the last break character
- int lineStart = 0; // character index of the line start
- float nextStart = 0.0; // total width of the current line
- float breakWidth = 0.0; // width of the line up to the last word break
- float currentWidth = 0.0; // width of all characters on the current line
- float prevWidth; // width of all characters but the current glyph
- float wordLength = 0.0; // length of the block since the last break char
- float glyphWidth, advance;
- FTBBox glyphBounds;
-
- // Reset the pen position
- pen.Y(0);
-
- // If we have bounds mark them invalid
- if(bounds)
- {
- bounds->Invalidate();
- }
-
- // Scan the input for all characters that need output
- for(int i = 0; buf[i]; i++)
- {
- // Find the width of the current glyph
- CheckGlyph(currentFont, buf[i]);
- glyphBounds = GetGlyphs(currentFont)->BBox(buf[i]);
- glyphWidth = glyphBounds.upperX - glyphBounds.lowerX;
-
- advance = GetGlyphs(currentFont)->Advance(buf[i], buf[i + 1]);
- prevWidth = currentWidth;
- // Compute the width of all glyphs up to the end of buf[i]
- currentWidth = nextStart + glyphWidth;
- // Compute the position of the next glyph
- nextStart += advance;
-
- // See if buf[i] is a space, a break or a regular character
- if((currentWidth > lineLength) || (buf[i] == '\n'))
- {
- // A non whitespace character has exceeded the line length. Or a
- // newline character has forced a line break. Output the last
- // line and start a new line after the break character.
- // If we have not yet found a break, break on the last character
- if(!breakIdx || (buf[i] == '\n'))
- {
- // Break on the previous character
- breakIdx = i - 1;
- breakWidth = prevWidth;
- // None of the previous words will be carried to the next line
- wordLength = 0;
- // If the current character is a newline discard its advance
- if(buf[i] == '\n') advance = 0;
- }
-
- float remainingWidth = lineLength - breakWidth;
-
- // Render the current substring
- // If the break character is a newline do not render it
- if(buf[breakIdx + 1] == '\n')
- {
- breakIdx++;
- OutputWrapped(buf, lineStart, breakIdx - 1,
- remainingWidth, bounds);
- }
- else
- {
- OutputWrapped(buf, lineStart, breakIdx, remainingWidth, bounds);
- }
-
- // Store the start of the next line
- lineStart = breakIdx + 1;
- // TODO: Is Height() the right value here?
- pen.Y(pen.Y() - GetCharSize(currentFont).Height() * lineSpacing);
- // The current width is the width since the last break
- nextStart = wordLength + advance;
- wordLength += advance;
- currentWidth = wordLength + advance;
- // Reset the safe break for the next line
- breakIdx = 0;
- }
- else if(isspace(buf[i]))
- {
- // This is the last word break position
- wordLength = 0;
- breakIdx = i;
+ WrapTextI(buf, bounds);
+}
- // Check to see if this is the first whitespace character in a run
- if(!i || !isspace(buf[i - 1]))
- {
- // Record the width of the start of the block
- breakWidth = currentWidth;
- }
- }
- else
- {
- wordLength += advance;
- }
- }
- float remainingWidth = lineLength - currentWidth;
- // Render any remaining text on the last line
- // Disable justification for the last row
- if(alignment == ALIGN_JUST)
- {
- alignment = ALIGN_LEFT;
- OutputWrapped(buf, lineStart, -1, remainingWidth, bounds);
- alignment = ALIGN_JUST;
- }
- else
- {
- OutputWrapped(buf, lineStart, -1, remainingWidth, bounds);
- }
+void FTSimpleLayout::WrapText(const wchar_t* buf, FTBBox *bounds)
+{
+ WrapTextI(buf, bounds);
}
-void FTSimpleLayout::OutputWrapped(const char *buf, const int start,
- const int end, const float RemainingWidth,
- FTBBox *bounds)
+template <typename T>
+inline void FTSimpleLayout::OutputWrappedI(const T *buf, const int start,
+ const int end,
+ const float RemainingWidth,
+ FTBBox *bounds)
{
float distributeWidth = 0.0;
// Align the text according as specified by Alignment
@@ -375,63 +285,25 @@ void FTSimpleLayout::OutputWrapped(const char *buf, const int start,
}
-void FTSimpleLayout::OutputWrapped(const wchar_t *buf, const int start,
+void FTSimpleLayout::OutputWrapped(const char *buf, const int start,
const int end, const float RemainingWidth,
FTBBox *bounds)
{
- float distributeWidth = 0.0;
- // Align the text according as specified by Alignment
- switch (alignment)
- {
- case ALIGN_LEFT:
- pen.X(0);
- break;
- case ALIGN_CENTER:
- pen.X(RemainingWidth / 2);
- break;
- case ALIGN_RIGHT:
- pen.X(RemainingWidth);
- break;
- case ALIGN_JUST:
- pen.X(0);
- distributeWidth = RemainingWidth;
- break;
- }
-
- // If we have bounds expand them by the line's bounds, otherwise render
- // the line.
- if(bounds)
- {
- float llx, lly, llz, urx, ury, urz;
- currentFont->BBox(buf, start, end, llx, lly, llz, urx, ury, urz);
+ OutputWrappedI(buf, start, end, RemainingWidth, bounds);
+}
- // Add the extra space to the upper x dimension
- urx += distributeWidth;
- // TODO: It's a little silly to convert from a FTBBox to floats and
- // back again, but I don't want to implement yet another method for
- // finding the bounding box as a BBox.
- FTBBox temp(llx, lly, llz, urx, ury, urz);
- temp.Move(FTPoint(pen.X(), pen.Y(), 0.0f));
- // See if this is the first area to be added to the bounds
- if(!bounds->IsValid())
- {
- *bounds = temp;
- }
- else
- {
- *bounds += temp;
- }
- }
- else
- {
- RenderSpace(buf, start, end, distributeWidth);
- }
+void FTSimpleLayout::OutputWrapped(const wchar_t *buf, const int start,
+ const int end, const float RemainingWidth,
+ FTBBox *bounds)
+{
+ OutputWrappedI(buf, start, end, RemainingWidth, bounds);
}
-void FTSimpleLayout::RenderSpace(const char *string, const int start,
- const int end, const float ExtraSpace)
+template <typename T>
+inline void FTSimpleLayout::RenderSpaceI(const T *string, const int start,
+ const int end, const float ExtraSpace)
{
float space = 0.0;
@@ -470,42 +342,16 @@ void FTSimpleLayout::RenderSpace(const char *string, const int start,
}
-void FTSimpleLayout::RenderSpace(const wchar_t *string, const int start,
+void FTSimpleLayout::RenderSpace(const char *string, const int start,
const int end, const float ExtraSpace)
{
- float space = 0.0;
-
- // If there is space to distribute, count the number of spaces
- if(ExtraSpace > 0.0)
- {
- int numSpaces = 0;
-
- // Count the number of space blocks in the input
- for(int i = start; ((end < 0) && string[i])
- || ((end >= 0) && (i <= end)); i++)
- {
- // If this is the end of a space block, increment the counter
- if((i > start) && !isspace(string[i]) && isspace(string[i - 1]))
- {
- numSpaces++;
- }
- }
+ RenderSpaceI(string, start, end, ExtraSpace);
+}
- space = ExtraSpace/numSpaces;
- }
- // Output all characters of the string
- for(int i = start; ((end < 0) && string[i])
- || ((end >= 0) && (i <= end)); i++)
- {
- // If this is the end of a space block, distribute the extra space
- // inside it
- if((i > start) && !isspace(string[i]) && isspace(string[i - 1]))
- {
- pen.X(pen.X() + space);
- }
-
- DoRender(currentFont, string[i], string[i + 1]);
- }
+void FTSimpleLayout::RenderSpace(const wchar_t *string, const int start,
+ const int end, const float ExtraSpace)
+{
+ RenderSpaceI(string, start, end, ExtraSpace);
}