1
1
/*
2
2
CGUITTFont FreeType class for Irrlicht
3
3
Copyright (c) 2009-2010 John Norman
4
+ Copyright (c) 2016 Nathanaël Courant
4
5
5
6
This software is provided 'as-is', without any express or implied
6
7
warranty. In no event will the authors be held liable for any
@@ -545,6 +546,13 @@ void CGUITTFont::setFontHinting(const bool enable, const bool enable_auto_hintin
545
546
546
547
void CGUITTFont::draw (const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
547
548
{
549
+ draw (EnrichedString (std::wstring (text.c_str ()), color), position, color, hcenter, vcenter, clip);
550
+ }
551
+
552
+ void CGUITTFont::draw (const EnrichedString &text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
553
+ {
554
+ std::vector<video::SColor> colors = text.getColors ();
555
+
548
556
if (!Driver)
549
557
return ;
550
558
@@ -572,7 +580,7 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
572
580
}
573
581
574
582
// Convert to a unicode string.
575
- core::ustring utext ( text);
583
+ core::ustring utext = text. getString ( );
576
584
577
585
// Set up our render map.
578
586
core::map<u32, CGUITTGlyphPage*> Render_Map;
@@ -581,6 +589,7 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
581
589
u32 n;
582
590
uchar32_t previousChar = 0 ;
583
591
core::ustring::const_iterator iter (utext);
592
+ std::vector<video::SColor> applied_colors;
584
593
while (!iter.atEnd ())
585
594
{
586
595
uchar32_t currentChar = *iter;
@@ -590,7 +599,7 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
590
599
if (currentChar == L' \r ' ) // Mac or Windows breaks
591
600
{
592
601
lineBreak = true ;
593
- if (*(iter + 1 ) == (uchar32_t )' \n ' ) // Windows line breaks.
602
+ if (*(iter + 1 ) == (uchar32_t )' \n ' ) // Windows line breaks.
594
603
currentChar = *(++iter);
595
604
}
596
605
else if (currentChar == (uchar32_t )' \n ' ) // Unix breaks
@@ -627,6 +636,9 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
627
636
page->render_positions .push_back (core::position2di (offset.X + offx, offset.Y + offy));
628
637
page->render_source_rects .push_back (glyph.source_rect );
629
638
Render_Map.set (glyph.glyph_page , page);
639
+ u32 current_color = iter.getPos ();
640
+ if (current_color < colors.size ())
641
+ applied_colors.push_back (colors[current_color]);
630
642
}
631
643
offset.X += getWidthFromCharacter (currentChar);
632
644
@@ -645,16 +657,24 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
645
657
646
658
CGUITTGlyphPage* page = n->getValue ();
647
659
648
- if (!use_transparency) color.color |= 0xff000000 ;
649
-
650
660
if (shadow_offset) {
651
661
for (size_t i = 0 ; i < page->render_positions .size (); ++i)
652
662
page->render_positions [i] += core::vector2di (shadow_offset, shadow_offset);
653
663
Driver->draw2DImageBatch (page->texture , page->render_positions , page->render_source_rects , clip, video::SColor (shadow_alpha,0 ,0 ,0 ), true );
654
664
for (size_t i = 0 ; i < page->render_positions .size (); ++i)
655
665
page->render_positions [i] -= core::vector2di (shadow_offset, shadow_offset);
656
666
}
657
- Driver->draw2DImageBatch (page->texture , page->render_positions , page->render_source_rects , clip, color, true );
667
+ for (size_t i = 0 ; i < page->render_positions .size (); ++i) {
668
+ irr::video::SColor col;
669
+ if (!applied_colors.empty ()) {
670
+ col = applied_colors[i < applied_colors.size () ? i : 0 ];
671
+ } else {
672
+ col = irr::video::SColor (255 , 255 , 255 , 255 );
673
+ }
674
+ if (!use_transparency)
675
+ col.color |= 0xff000000 ;
676
+ Driver->draw2DImage (page->texture , page->render_positions [i], page->render_source_rects [i], clip, col, true );
677
+ }
658
678
}
659
679
}
660
680
0 commit comments