- Added FTLayout.h, FTSimpleLayout.h and FTSimpleLayout.cpp to implement a framework for layout managers and an implementation of a simple layout manager.
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
diff --git a/include/FTLayout.h b/include/FTLayout.h
new file mode 100644
index 0000000..43f0410
--- /dev/null
+++ b/include/FTLayout.h
@@ -0,0 +1,107 @@
+#ifndef __FTLayout__
+#define __FTLayout__
+
+#include "FTGL.h"
+#include "FTPoint.h"
+#include "FTFont.h"
+
+/**
+ * FTLayout is the interface for layout managers that render text.
+ *
+ * Specific layout manager classes are derived from this class. This class
+ * is abstract and deriving classes must implement the protected
+ * <code>Render</code> methods to render formatted text and
+ * <code>BBox</code> methods to determine the bounding box of output text.
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTLayout {
+ public:
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string a char string
+ * @param llx lower left near x coord
+ * @param lly lower left near y coord
+ * @param llz lower left near z coord
+ * @param urx upper right far x coord
+ * @param ury upper right far y coord
+ * @param urz upper right far z coord
+ */
+ virtual void BBox(const char* String,float& llx,float& lly,float& llz,float& urx,float& ury,float& urz) = 0;
+
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string a wchar_t string
+ * @param llx lower left near x coord
+ * @param lly lower left near y coord
+ * @param llz lower left near z coord
+ * @param urx upper right far x coord
+ * @param ury upper right far y coord
+ * @param urz upper right far z coord
+ */
+ virtual void BBox(const wchar_t* String,float& llx,float& lly,float& llz,float& urx,float& ury,float& urz) = 0;
+
+ /**
+ * Render a string of characters
+ *
+ * @param string 'C' style string to be output.
+ */
+ virtual void Render(const char *String) = 0;
+
+ /**
+ * Render a string of characters
+ *
+ * @param string wchar_t string to be output.
+ */
+ virtual void Render(const wchar_t *String) = 0;
+ protected:
+ /**
+ * Current pen or cursor position;
+ */
+ FTPoint pen;
+
+ /**
+ * Expose <code>FTFont::DoRender</code> method to derived classes.
+ *
+ * @param font The font that contains the glyph.
+ * @param chr current character
+ * @param nextChr next character
+ * @see FTFont::DoRender
+ */
+ void DoRender(FTFont *font,const unsigned int chr,const unsigned int nextChr)
+ { font->DoRender(chr,nextChr,pen); }
+
+ /**
+ * Expose <code>FTFont::CheckGlyph</code> method to derived classes.
+ *
+ * @param font The font that contains the glyph.
+ * @param chr character index
+ */
+ void CheckGlyph(FTFont *font,const unsigned int Chr)
+ { font->CheckGlyph(Chr); }
+
+ /**
+ * Expose the FTFont <code>glyphList</code> to our derived classes.
+ *
+ * @param font The font to perform the query on.
+ * @param Char The character corresponding to the glyph to query.
+ *
+ * @return A pointer to the glyphList of font.
+ */
+ FTGlyphContainer *GetGlyphs(FTFont *font)
+ { return(font->glyphList); }
+
+ /**
+ * Expose the FTFont <code>charSize</code> to our derived classes.
+ *
+ * @param The font to perform the query on.
+ *
+ * @return A reference to the charSize object of font.
+ */
+ FTSize &GetCharSize(FTFont *font)
+ { return(font->charSize); }
+}; /* class FTLayout */
+#endif /* __FTLayout__ */
+
diff --git a/include/FTSimpleLayout.h b/include/FTSimpleLayout.h
new file mode 100644
index 0000000..665e6cf
--- /dev/null
+++ b/include/FTSimpleLayout.h
@@ -0,0 +1,262 @@
+#ifndef __FTSimpleLayout__
+#define __FTSimpleLayout__
+
+#include "FTLayout.h"
+#include "FTBBox.h"
+
+class FTFont;
+
+class FTGL_EXPORT FTSimpleLayout : public FTLayout {
+ public:
+ /**
+ * Initializes line spacing to 1.0, alignment to
+ * ALIGN_LEFT and wrap to 100.0
+ */
+ FTSimpleLayout();
+
+ /**
+ * Get the bounding box for a string.
+ *
+ * @param string a char string
+ * @param llx lower left near x coord
+ * @param lly lower left near y coord
+ * @param llz lower left near z coord
+ * @param urx upper right far x coord
+ * @param ury upper right far y coord
+ * @param urz upper right far z coord
+ */
+ virtual void BBox( const char* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz);
+
+ /**
+ * Get the bounding box for a string.
+ *
+ * @param string a wchar_t string
+ * @param llx lower left near x coord
+ * @param lly lower left near y coord
+ * @param llz lower left near z coord
+ * @param urx upper right far x coord
+ * @param ury upper right far y coord
+ * @param urz upper right far z coord
+ */
+ virtual void BBox( const wchar_t* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz);
+
+ /**
+ * Render a string of characters
+ *
+ * @param string 'C' style string to be output.
+ */
+ 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 );
+
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string.
+ *
+ * @param String 'C' style string to output.
+ * @param ExtraSpace The amount of extra space to add to each run of
+ * whitespace.
+ */
+ void RenderSpace(const char *String,const float ExtraSpace = 0.0)
+ { pen.x = 0; pen.y = 0; RenderSpace(String,0,-1,ExtraSpace); }
+
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string.
+ *
+ * @param String wchar_t string to output.
+ * @param ExtraSpace The amount of extra space to add to each run of
+ * whitespace.
+ */
+ void RenderSpace(const wchar_t *String,const float ExtraSpace = 0.0)
+ { pen.x = 0; pen.y = 0; RenderSpace(String,0,-1,ExtraSpace); }
+
+ typedef enum {ALIGN_LEFT,ALIGN_CENTER,ALIGN_RIGHT,ALIGN_JUST} TextAlignment;
+
+ /**
+ * Set he font to use for rendering the text.
+ *
+ * @param fontInit A pointer to the new font. The font is
+ * referenced by this but will not be
+ * disposed of when this is deleted.
+ */
+ void SetFont(FTFont *fontInit)
+ { currentFont = fontInit; }
+ /**
+ * @return The current font.
+ */
+ FTFont *GetFont()
+ { return(currentFont); }
+ /**
+ * The maximum line length for formatting text.
+ *
+ * @param LineLength The new line length.
+ */
+ void SetLineLength(const float LineLength)
+ { lineLength = LineLength; }
+
+ /**
+ * @return The current line length.
+ */
+ float GetLineLength() const
+ { return(lineLength); }
+
+ /**
+ * The text alignment mode used to distribute
+ * space within a line or rendered text.
+ *
+ * @param Alignment The new alignment mode.
+ */
+ void SetAlignment(const TextAlignment Alignment)
+ { alignment = Alignment; }
+ /**
+ * @return The text alignment mode.
+ */
+ TextAlignment GetAlignment() const
+ { return(alignment); }
+
+ /**
+ * Sets the line height.
+ *
+ * @param LineSpacing The height of each line of text expressed as
+ * a percentage of the current fonts line height.
+ */
+ void SetLineSpacing(const float LineSpacing)
+ { lineSpacing = LineSpacing; }
+
+ /**
+ * @return The line spacing.
+ */
+ float GetLineSpacing() const
+ { return(lineSpacing); }
+ protected:
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string. Note that this method
+ * does not reset the pen position before rendering. This method
+ * provides the impelmentation for other RenderSpace methods and
+ * thus should be overloaded when attempting to overload any
+ * RenderSpace methods.
+ *
+ * @param String A buffer of wchar_t characters to output.
+ * @param Start The index of the first character in String to output.
+ * @param Stop The index of the last character in String to output.
+ * @param ExtraSpace The amount of extra space to distribute amongst
+ * the characters.
+ */
+ virtual void RenderSpace(const char *String,const int Start,const int Stop,const float ExtraSpace = 0.0);
+
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string. Note that this method
+ * does not reset the pen position before rendering. This method
+ * provides the impelmentation for other RenderSpace methods and
+ * thus should be overloaded when attempting to overload any
+ * RenderSpace methods.
+ *
+ * @param String A buffer of wchar_t characters to output.
+ * @param Start The index of the first character in String to output.
+ * @param Stop The index of the last character in String to output.
+ * @param ExtraSpace The amount of extra space to distribute amongst
+ * the characters.
+ */
+ virtual void RenderSpace(const wchar_t *String,const int Start,const int Stop,const float ExtraSpace = 0.0);
+ private:
+ /**
+ * Either render a string of characters and wrap lines
+ * longer than a threshold or compute the bounds
+ * of a string of characters when wrapped. The functionality
+ * of this method is exposed by the BBoxWrapped and
+ * RenderWrapped methods.
+ *
+ * @param Buffer wchar_t style string to output.
+ * @param bounds A pointer to a bounds object. If non null
+ * the bounds of the text when laid out
+ * will be stored in bounds. If null the
+ * text will be rendered.
+ */
+ virtual void WrapText(const char *Buffer,FTBBox *bounds = NULL);
+
+ /**
+ * Either render a string of characters and wrap lines
+ * longer than a threshold or compute the bounds
+ * of a string of characters when wrapped. The functionality
+ * of this method is exposed by the BBoxWrapped and
+ * RenderWrapped methods.
+ *
+ * @param Buffer wchar_t style string to output.
+ * @param bounds A pointer to a bounds object. If non null
+ * the bounds of the text when laid out
+ * will be stored in bounds. If null the
+ * text will be rendered.
+ */
+ virtual void WrapText(const wchar_t *Buffer,FTBBox *bounds = NULL);
+
+ /**
+ * A helper method used by WrapText to either output the text or
+ * compute it's bounds.
+ *
+ * @param Buffer A pointer to an array of character data.
+ * @param StartIdx The index of the first character to process.
+ * @param EndIdx The index of the last character to process. If
+ * < 0 then characters will be parsed until a '\0'
+ * is encountered.
+ * @param RemainingWidth The amount of extra space left on the line.
+ * @param bounds A pointer to a bounds object. If non null the
+ * bounds will be initialized or expanded by the
+ * bounds of the line. If null the text will be
+ * rendered. If the bounds are invalid (lower > upper)
+ * they will be initialized. Otherwise they
+ * will be expanded.
+ */
+ void OutputWrapped(const char *Buffer,const int StartIdx,const int EndIdx,const float RemainingWidth,FTBBox *bounds);
+
+ /**
+ * A helper method used by WrapText to either output the text or
+ * compute it's bounds.
+ *
+ * @param Buffer A pointer to an array of character data.
+ * @param StartIdx The index of the first character to process.
+ * @param EndIdx The index of the last character to process. If
+ * < 0 then characters will be parsed until a '\0'
+ * is encountered.
+ * @param RemainingWidth The amount of extra space left on the line.
+ * @param bounds A pointer to a bounds object. If non null the
+ * bounds will be initialized or expanded by the
+ * bounds of the line. If null the text will be
+ * rendered. If the bounds are invalid (lower > upper)
+ * they will be initialized. Otherwise they
+ * will be expanded.
+ */
+ void OutputWrapped(const wchar_t *Buffer,const int StartIdx,const int EndIdx,const float RemainingWidth,FTBBox *bounds);
+
+ /**
+ * The font to use for rendering the text. The font is
+ * referenced by this but will not be disposed of when this
+ * is deleted.
+ */
+ FTFont *currentFont;
+ /**
+ * The maximum line length for formatting text.
+ */
+ float lineLength;
+
+ /**
+ * The text alignment mode used to distribute
+ * space within a line or rendered text.
+ */
+ TextAlignment alignment;
+
+ /**
+ * The height of each line of text expressed as
+ * a percentage of the fonts line height.
+ */
+ float lineSpacing;
+}; /* class FTSimpleLayout */
+#endif /* __FTSimpleLayout__ */
+
diff --git a/src/FTSimpleLayout.cpp b/src/FTSimpleLayout.cpp
new file mode 100644
index 0000000..c28bd6d
--- /dev/null
+++ b/src/FTSimpleLayout.cpp
@@ -0,0 +1,347 @@
+#include "FTSimpleLayout.h"
+
+#include "FTFont.h"
+#include "FTGlyphContainer.h"
+#include "FTBBox.h"
+
+#include <ctype.h>
+
+
+FTSimpleLayout::FTSimpleLayout() {
+ currentFont = NULL;
+ lineLength = 100.0f;
+ alignment = ALIGN_LEFT;
+ lineSpacing = 1.0f;
+} /* FTSimpleLayout::FTSimpleLayout() */
+
+void FTSimpleLayout::BBox(const char *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) {
+ FTBBox bounds;
+
+ WrapText(String,&bounds);
+ llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
+ urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
+} /* FTSimpleLayout::BBox() */
+
+void FTSimpleLayout::BBox(const wchar_t *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) {
+ FTBBox bounds;
+
+ WrapText(String,&bounds);
+ llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
+ urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
+} /* FTSimpleLayout::BBox() */
+
+void FTSimpleLayout::Render(const char *String) {
+ pen.x = pen.y = 0.0f;
+ WrapText(String,NULL);
+} /* FTSimpleLayout::Render() */
+
+void FTSimpleLayout::Render(const wchar_t* String) {
+ pen.x = pen.y = 0.0f;
+ WrapText(String,NULL);
+} /* FTSimpleLayout::Render() */
+
+void FTSimpleLayout::WrapText(const char *Buffer,FTBBox *bounds) {
+ int breakIdx = 0; // The index of the last break character
+ int lineStart = 0; // The character index of the line start
+ float nextStart = 0.0; // The total width of the line being generated
+ float breakWidth = 0.0; // The width of the line up to the last word break
+ float currentWidth = 0.0; // The width of all characters on the line being generated
+ float prevWidth; // The width of all characters but the current glyph
+ float wordLength = 0.0; // The length of the block since the last break character
+ float glyphWidth,advance;
+ FTBBox glyphBounds;
+ /* Reset the pen position */
+ pen.y = 0;
+
+ if (bounds) {
+ bounds->Invalidate();
+ } /* If we have bounds mark them invalid (if bounds) */
+
+ for (int charIdx = 0;Buffer[charIdx];charIdx++) {
+ /* Find the width of the current glyph */
+ CheckGlyph(currentFont,Buffer[charIdx]);
+ glyphBounds = GetGlyphs(currentFont)->BBox(Buffer[charIdx]);
+ glyphWidth = glyphBounds.upperX - glyphBounds.lowerX;
+
+ advance = GetGlyphs(currentFont)->Advance(Buffer[charIdx],Buffer[charIdx + 1]);
+ prevWidth = currentWidth;
+ /* Compute the width of all glyphs up to the end of Buffer[charIdx] */
+ currentWidth = nextStart + glyphWidth;
+ /* Compute the position of the next glyph */
+ nextStart += advance;
+
+ if ((currentWidth > lineLength) || (Buffer[charIdx] == '\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 (!breakIdx || (Buffer[charIdx] == '\n')) {
+ /* Break on the previous character */
+ breakIdx = charIdx - 1;
+ breakWidth = prevWidth;
+ /* None of the previous word will be carried to the next line */
+ wordLength = 0;
+ /* If the current character is a newline discard it's advance */
+ if (Buffer[charIdx] == '\n') advance = 0;
+ } /* If we have not yet found a break break on the last character (if !breakIdx) */
+
+ float remainingWidth = lineLength - breakWidth;
+
+ /* Render the current substring */
+ if (Buffer[breakIdx + 1] == '\n') {
+ breakIdx++;
+ OutputWrapped(Buffer,lineStart,breakIdx -1,remainingWidth,bounds);
+ } else {
+ OutputWrapped(Buffer,lineStart,breakIdx ,remainingWidth,bounds);
+ } /* If the break character is a newline do not render it (if Buffer[charIdx]) */
+
+ /* Store the start of the next line */
+ lineStart = breakIdx + 1;
+ // TODO: Is Height() the right value here?
+ 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(Buffer[charIdx])) {
+ /* This is the last word break position */
+ wordLength = 0;
+ breakIdx = charIdx;
+
+ if (!charIdx || !isspace(Buffer[charIdx - 1])) {
+ /* Record the width of the start of the block */
+ breakWidth = currentWidth;
+ } /* Check to see if this is the first whitespace character in a run (if !isspace()) */
+ } else {
+ wordLength += advance;
+ } /* See if Buffer[charIdx] is a space, a break or a regular charactger (if/elseif/else Buffer[]) */
+ } /* Scan the input for all characters that need output (for charIdx) */
+
+ float remainingWidth = lineLength - currentWidth;
+ /* Render any remaining text on the last line */
+ if (alignment == ALIGN_JUST) {
+ alignment = ALIGN_LEFT;
+ OutputWrapped(Buffer,lineStart,-1,remainingWidth,bounds);
+ alignment = ALIGN_JUST;
+ } else {
+ OutputWrapped(Buffer,lineStart,-1,remainingWidth,bounds);
+ } /* Disable justification for the last row (if/else Alignemnt) */
+} /* FTSimpleLayout::WrapText() */
+
+void FTSimpleLayout::WrapText(const wchar_t* Buffer,FTBBox *bounds) {
+ int breakIdx = 0; // The index of the last break character
+ int lineStart = 0; // The character index of the line start
+ float nextStart = 0.0; // The total width of the line being generated
+ float breakWidth = 0.0; // The width of the line up to the last word break
+ float currentWidth = 0.0; // The width of all characters on the line being generated
+ float prevWidth; // The width of all characters but the current glyph
+ float wordLength = 0.0; // The length of the block since the last break character
+ float glyphWidth,advance;
+ FTBBox glyphBounds;
+ /* Reset the pen position */
+ pen.y = 0;
+
+ if (bounds) {
+ bounds->Invalidate();
+ } /* If we have bounds mark them invalid (if bounds) */
+
+ for (int charIdx = 0;Buffer[charIdx];charIdx++) {
+ /* Find the width of the current glyph */
+ CheckGlyph(currentFont,Buffer[charIdx]);
+ glyphBounds = GetGlyphs(currentFont)->BBox(Buffer[charIdx]);
+ glyphWidth = glyphBounds.upperX - glyphBounds.lowerX;
+
+ advance = GetGlyphs(currentFont)->Advance(Buffer[charIdx],Buffer[charIdx + 1]);
+ prevWidth = currentWidth;
+ /* Compute the width of all glyphs up to the end of Buffer[charIdx] */
+ currentWidth = nextStart + glyphWidth;
+ /* Compute the position of the next glyph */
+ nextStart += advance;
+
+ if ((currentWidth > lineLength) || (Buffer[charIdx] == '\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 (!breakIdx || (Buffer[charIdx] == '\n')) {
+ /* Break on the previous character */
+ breakIdx = charIdx - 1;
+ breakWidth = prevWidth;
+ /* None of the previous word will be carried to the next line */
+ wordLength = 0;
+ /* If the current character is a newline discard it's advance */
+ if (Buffer[charIdx] == '\n') advance = 0;
+ } /* If we have not yet found a break break on the last character (if !breakIdx) */
+
+ float remainingWidth = lineLength - breakWidth;
+
+ /* Render the current substring */
+ if (Buffer[breakIdx + 1] == '\n') {
+ breakIdx++;
+ OutputWrapped(Buffer,lineStart,breakIdx -1,remainingWidth,bounds);
+ } else {
+ OutputWrapped(Buffer,lineStart,breakIdx ,remainingWidth,bounds);
+ } /* If the break character is a newline do not render it (if Buffer[charIdx]) */
+
+ /* Store the start of the next line */
+ lineStart = breakIdx + 1;
+ // TODO: Is Height() the right value here?
+ 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(Buffer[charIdx])) {
+ /* This is the last word break position */
+ wordLength = 0;
+ breakIdx = charIdx;
+
+ if (!charIdx || !isspace(Buffer[charIdx - 1])) {
+ /* Record the width of the start of the block */
+ breakWidth = currentWidth;
+ } /* Check to see if this is the first whitespace character in a run (if !isspace()) */
+ } else {
+ wordLength += advance;
+ } /* See if Buffer[charIdx] is a space, a break or a regular charactger (if/elseif/else Buffer[]) */
+ } /* Scan the input for all characters that need output (for charIdx) */
+
+ float remainingWidth = lineLength - currentWidth;
+ /* Render any remaining text on the last line */
+ if (alignment == ALIGN_JUST) {
+ alignment = ALIGN_LEFT;
+ OutputWrapped(Buffer,lineStart,-1,remainingWidth,bounds);
+ alignment = ALIGN_JUST;
+ } else {
+ OutputWrapped(Buffer,lineStart,-1,remainingWidth,bounds);
+ } /* Disable justification for the last row (if/else Alignemnt) */
+} /* FTSimpleLayout::WrapText() */
+
+void FTSimpleLayout::OutputWrapped(const char *Buffer,const int StartIdx,const int EndIdx,const float RemainingWidth,FTBBox *bounds) {
+ float distributeWidth = 0.0;
+ 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;
+ } /* Allign the text according as specified by Alignment (switch Alignment) */
+
+ if (bounds) {
+ float llx,lly,llz,urx,ury,urz;
+ currentFont->BBox(Buffer,StartIdx,EndIdx,llx,lly,llz,urx,ury,urz);
+
+ /* 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));
+
+ if (!bounds->IsValid()) {
+ *bounds = temp;
+ } else {
+ *bounds += temp;
+ } /* See if this is the first area to be added to the bounds (if/else bounds) */
+ } else {
+ RenderSpace(Buffer,StartIdx,EndIdx,distributeWidth);
+ } /* If we have bounds expand them by the lines bounds, otherwise render the line (if/else bounds) */
+} /* FTSimpleLayout::OutputWrapped() */
+
+void FTSimpleLayout::OutputWrapped(const wchar_t *Buffer,const int StartIdx,const int EndIdx,const float RemainingWidth,FTBBox *bounds) {
+ float distributeWidth = 0.0;
+ 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;
+ } /* Allign the text according as specified by Alignment (switch Alignment) */
+
+ if (bounds) {
+ float llx,lly,llz,urx,ury,urz;
+ currentFont->BBox(Buffer,StartIdx,EndIdx,llx,lly,llz,urx,ury,urz);
+
+ /* 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));
+
+ if (!bounds->IsValid()) {
+ *bounds = temp;
+ } else {
+ *bounds += temp;
+ } /* See if this is the first area to be added to the bounds (if/else bounds) */
+ } else {
+ RenderSpace(Buffer,StartIdx,EndIdx,distributeWidth);
+ } /* If we have bounds expand them by the lines bounds, otherwise render the line (if/else bounds) */
+} /* FTSimpleLayout::OutputWrapped() */
+
+void FTSimpleLayout::RenderSpace(const char *String,const int StartIdx,const int EndIdx,const float ExtraSpace) {
+ float space = 0.0;
+
+ if (ExtraSpace > 0.0) {
+ int numSpaces = 0;
+
+ for (int idx = StartIdx;((EndIdx < 0) && String[idx]) || ((EndIdx >= 0) && (idx <= EndIdx));idx++) {
+ if ((idx > StartIdx) && !isspace(String[idx]) && isspace(String[idx - 1])) {
+ numSpaces++;
+ } /* If this is the end of a space block increment the counter (if isspace()) */
+ } /* Count the number of space blocks in the input (for idx) */
+
+ space = ExtraSpace/numSpaces;
+ } /* If there is space to distribute count the number of spaces (if ExtraSpace) */
+
+ for (int idx = StartIdx;((EndIdx < 0) && String[idx]) || ((EndIdx >= 0) && (idx <= EndIdx));idx++) {
+ if ((idx > StartIdx) && !isspace(String[idx]) && isspace(String[idx - 1])) {
+ pen.x += space;
+ } /* If this is the end of a space block distribute the extra space into it (if isspace()) */
+
+ DoRender(currentFont,String[idx],String[idx + 1]);
+ } /* Output all characters of the string (for idx) */
+} /* FTSimpleLayout::RenderSpace() */
+
+void FTSimpleLayout::RenderSpace(const wchar_t *String,const int StartIdx,const int EndIdx,const float ExtraSpace) {
+ float space = 0.0;
+
+ if (ExtraSpace > 0.0) {
+ int numSpaces = 0;
+
+ for (int idx = StartIdx;((EndIdx < 0) && String[idx]) || ((EndIdx >= 0) && (idx <= EndIdx));idx++) {
+ if ((idx > StartIdx) && !isspace(String[idx]) && isspace(String[idx - 1])) {
+ numSpaces++;
+ } /* If this is the end of a space block increment the counter (if isspace()) */
+ } /* Count the number of space blocks in the input (for idx) */
+
+ space = ExtraSpace/numSpaces;
+ } /* If there is space to distribute count the number of spaces (if ExtraSpace) */
+
+ for (int idx = StartIdx;((EndIdx < 0) && String[idx]) || ((EndIdx >= 0) && (idx <= EndIdx));idx++) {
+ if ((idx > StartIdx) && !isspace(String[idx]) && isspace(String[idx - 1])) {
+ pen.x += space;
+ } /* If this is the end of a space block distribute the extra space into it (if isspace()) */
+
+ DoRender(currentFont,String[idx],String[idx + 1]);
+ } /* Output all characters of the string (for idx) */
+} /* FTSimpleLayout::RenderSpace() */