Gorgon Game Engine
Font.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <map>
5 #include <limits.h>
6 
7 #include "../Types.h"
8 #include "../Geometry/Point.h"
9 #include "../Geometry/Size.h"
10 #include "TextureTargets.h"
11 #include "Color.h"
12 
13 namespace Gorgon { namespace Graphics {
16 
18  class GlyphRange {
19  public:
22  /*implicit*/ GlyphRange(Glyph value = 0xFFFF) : Start(value), End(value) { }
23 
24  GlyphRange(Glyph start, Glyph end) : Start(start), End(end) { }
25 
27  int Count() const {
28  if(Start == -1) return 0;
29 
30  return End - Start + 1;
31  }
32 
33  void Normalize() {
34  if(Start > End)
36  }
37 
40 
43  };
44 
47  namespace internal {
50  Glyph decode(std::string::const_iterator &it, std::string::const_iterator end);
51  bool isnewline(Glyph g);
52  bool isspaced(Glyph g);
53  bool isspace(Glyph g);
54  bool isadjustablespace(Glyph g);
55  bool isbreaking(Glyph g);
56 
57  inline int ceildiv(int v, float f) { return (int)std::ceil(v/f); }
58  inline int rounddiv(int v, float f) { return (int)std::round(v/f); }
59 
60  }
61 
67  class GlyphRenderer {
68  public:
69  virtual ~GlyphRenderer() { }
70 
71 
78  virtual void Render(Glyph chr, TextureTarget &target, Geometry::Pointf location, RGBAf color) const = 0;
79 
82  virtual Geometry::Size GetSize(Glyph chr) const = 0;
83 
86  virtual float GetCursorAdvance(Glyph g) const = 0;
87 
89  virtual bool Exists(Glyph g) const = 0;
90 
92  virtual bool IsASCII() const = 0;
93 
96  virtual bool IsFixedWidth() const = 0;
97 
101  virtual Geometry::Pointf KerningDistance(Glyph left, Glyph right) const = 0;
102 
104  virtual int GetEMSize() const = 0;
105 
107  virtual int GetMaxWidth() const = 0;
108 
112  virtual int GetHeight() const = 0;
113 
118  virtual std::pair<int, int> GetLetterHeight(bool asciionly = false) const = 0;
119 
122  virtual int GetDigitWidth() const = 0;
123 
125  virtual float GetBaseLine() const = 0;
126 
129  virtual float GetLineGap() const = 0;
130 
133  virtual float GetLineThickness() const = 0;
134 
136  virtual int GetUnderlineOffset() const = 0;
137 
139  virtual bool NeedsPrepare() const { return false; }
140 
143  virtual void Prepare(const std::string &) const { }
144  };
145 
152  class TextRenderer {
153  public:
154  virtual ~TextRenderer() { }
155 
158  void Print(TextureTarget &target, const std::string &text, Geometry::Pointf location) const {
159  print(target, text, location);
160  }
161 
162  void Print(TextureTarget &target, const std::string &text, Geometry::Point location) const {
163  print(target, text, location);
164  }
165 
166  void Print(TextureTarget &target, const std::string &text, int x, int y) const {
167  print(target, text, {x, y});
168  }
169 
170  void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const {
171  print(target, text, {location, w, 0}, align_override);
172  }
173 
174  void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w) const {
175  print(target, text, {location, w, 0});
176  }
177 
178  void Print(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const {
179  print(target, text, {x, y, w, 0}, align_override);
180  }
181 
182  void Print(TextureTarget &target, const std::string &text, int x, int y, int w) const {
183  print(target, text, {x, y, w, 0});
184  }
185 
186  void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const {
187  printnowrap(target, text, {location, w, 0}, align_override);
188  }
189 
190  void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w) const {
191  printnowrap(target, text, {location, w, 0});
192  }
193 
194  void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const {
195  printnowrap(target, text, {x, y, w, 0}, align_override);
196  }
197 
198  void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w) const {
199  printnowrap(target, text, {x, y, w, 0});
200  }
201 
202  void Print(TextureTarget &target, const std::string &text) {
203  print(target, text, {0, 0, target.GetTargetSize()});
204  }
205 
207  virtual bool IsReady() const = 0;
208 
211  virtual const GlyphRenderer &GetGlyphRenderer() const = 0;
212 
214  virtual int GetEMSize() const = 0;
215 
217  virtual float GetBaseLine() const = 0;
218 
220  virtual int GetHeight() const = 0;
221 
223  virtual Geometry::Size GetSize(const std::string &text) const = 0;
224 
226  virtual Geometry::Size GetSize(const std::string &text, int width) const = 0;
227 
229  virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const = 0;
230 
232  virtual int GetCharacterIndex(const std::string &text, int w, Geometry::Point location, bool wrap = true) const = 0;
233 
236  virtual Geometry::Rectangle GetPosition(const std::string &text, int index) const = 0;
237 
240  virtual Geometry::Rectangle GetPosition(const std::string &text, int w, int index, bool wrap = true) const = 0;
241 
242  protected:
243  virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const = 0;
244 
250  virtual void print(TextureTarget &target, const std::string &text,
251  Geometry::Rectangle location, TextAlignment align_override) const = 0;
252 
253  virtual void print(TextureTarget &target, const std::string &text,
254  Geometry::Rectangle location) const = 0;
255 
258  virtual void printnowrap(TextureTarget &target, const std::string &text,
259  Geometry::Rectangle location) const = 0;
260 
263  virtual void printnowrap(TextureTarget &target, const std::string &text,
264  Geometry::Rectangle location, TextAlignment align_override) const = 0;
265  };
266 
271  class BasicFont : public TextRenderer {
272  public:
274  defaultalign(defaultalign), color(color), renderer(&renderer) {
275  }
276 
277  using TextRenderer::Print;
278 
279 
280  void Print(TextureTarget &target, const std::string &text, RGBAf color) const {
281  print(target, text, {0, 0, target.GetTargetSize()}, color);
282  }
283 
284  void Print(TextureTarget &target, const std::string &text, Geometry::Point location, RGBAf color) const {
285  print(target, text, location, color);
286  }
287 
288  void Print(TextureTarget &target, const std::string &text, int x, int y, RGBAf color) const {
289  print(target, text, {x, y}, color);
290  }
291 
292  void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const {
293  print(target, text, {location, w, 0}, align_override, color);
294  }
295 
296  void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const {
297  print(target, text, {location, w, 0}, color);
298  }
299 
300  void Print(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const {
301  print(target, text, {x, y, w, 0}, align_override, color);
302  }
303 
304  void Print(TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const {
305  print(target, text, {x, y, w, 0}, color);
306  }
307 
308  void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const {
309  printnowrap(target, text, {location, w, 0}, align_override, color);
310  }
311 
312  void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const {
313  printnowrap(target, text, {location, w, 0}, color);
314  }
315 
316  void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const {
317  printnowrap(target, text, {x, y, w, 0}, align_override, color);
318  }
319 
320  void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const {
321  printnowrap(target, text, {x, y, w, 0}, color);
322  }
323 
326  defaultalign = value;
327  }
328 
331  return defaultalign;
332  }
333 
335  void SetColor(RGBAf value) {
336  color = value;
337  }
338 
340  RGBAf GetColor() const {
341  return color;
342  }
343 
344  virtual bool IsReady() const override {
345  return renderer != nullptr;
346  }
347 
348  virtual const GlyphRenderer &GetGlyphRenderer() const override {
349  return *renderer;
350  }
351 
352  virtual int GetEMSize() const override {
353  return renderer->GetEMSize();
354  }
355 
356  virtual float GetBaseLine() const override {
357  return renderer->GetBaseLine();
358  }
359 
360  virtual int GetHeight() const override {
361  return renderer->GetHeight();
362  }
363 
364  virtual Geometry::Size GetSize(const std::string &text) const override;
365 
366  virtual Geometry::Size GetSize(const std::string &text, int width) const override;
367 
368  virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const override;
369 
370  virtual int GetCharacterIndex(const std::string &text, int w, Geometry::Point location, bool wrap = true) const override;
371 
372  virtual Geometry::Rectangle GetPosition(const std::string& text, int index) const override;
373 
374  virtual Geometry::Rectangle GetPosition(const std::string& text, int w, int index, bool wrap = true) const override;
375 
376  protected:
377  virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const override {
378  print(target, text, location, color);
379  }
380 
381  virtual void print(TextureTarget &target, const std::string &text,
382  Geometry::Rectangle location, TextAlignment align) const override {
383  print(target, text, location, align, color);
384  }
385 
386  virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location, RGBAf color) const;
387 
388  virtual void print(TextureTarget &target, const std::string &text,
389  Geometry::Rectangle location, TextAlignment align, RGBAf color) const;
390 
391  virtual void printnowrap(TextureTarget &target, const std::string &text,
392  Geometry::Rectangle location, TextAlignment align, RGBAf color) const;
393 
394  virtual void printnowrap(TextureTarget &target, const std::string &text,
395  Geometry::Rectangle location, TextAlignment align) const override {
396  printnowrap(target, text, location, align, color);
397  }
398 
399  virtual void print(TextureTarget &target, const std::string &text,
400  Geometry::Rectangle location) const override {
401  print(target, text, location, defaultalign);
402  }
403 
404  virtual void print(TextureTarget &target, const std::string &text,
405  Geometry::Rectangle location, RGBAf color) const {
406  print(target, text, location, defaultalign, color);
407  }
408 
409  virtual void printnowrap(TextureTarget &target, const std::string &text,
410  Geometry::Rectangle location) const override {
411  printnowrap(target, text, location, defaultalign);
412  }
413 
414  virtual void printnowrap(TextureTarget &target, const std::string &text,
415  Geometry::Rectangle location, RGBAf color) const {
416  printnowrap(target, text, location, defaultalign, color);
417  }
418 
421 
424 
425  private:
426  const GlyphRenderer *renderer;
427  };
428 
432  class TextShadow {
433  public:
434 
435  enum ShadowType {
437  Flat
438  };
439 
440  TextShadow() = default;
441 
443 
445  type(type), color(color), offset(offset) {}
446 
448  type(Flat), color(color), offset(offset) {}
449 
451  RGBAf color = 0x80000000;
452  Geometry::Pointf offset = {1.f, 1.f};
453  };
454 
461  class StyledRenderer : public TextRenderer {
462  public:
465  StyledRenderer(GlyphRenderer &renderer, RGBAf color = 1.f, TextShadow shadow = {}) :
466  renderer(&renderer), color(color), shadow(shadow) {
467  tabwidth = renderer.GetMaxWidth() * 8;
468  }
469 
470  StyledRenderer() = default;
471 
473  return *renderer;
474  }
475 
476  void SetGlyphRenderer(GlyphRenderer &renderer) {
477  this->renderer = &renderer;
478  }
479 
481  void SetColor(RGBAf value) {
482  color = value;
483  }
484 
486  RGBAf GetColor() const {
487  return color;
488  }
489 
491  void SetShadow(TextShadow value) {
492  shadow = value;
493  }
494 
496  void DisableShadow() {
497  shadow = TextShadow::None;
498  }
499 
501  void UseFlatShadow(RGBAf color, Geometry::Pointf offset = {1.f, 1.f}) {
502  shadow = {TextShadow::Flat, color, offset};
503  }
504 
507  return shadow;
508  }
509 
511  void SetUnderline(bool value) {
512  underline = value;
513  }
514 
516  void Underline() {
517  underline = true;
518  }
519 
521  void Underline(RGBAf color) {
522  underline = true;
523  underlinecolor = color;
524  }
525 
527  bool GetUnderline() const {
528  return underline;
529  }
530 
534  void SetUnderlineColor(RGBAf value) {
535  underlinecolor = value;
536  }
537 
540  if(underlinecolor.R == -1)
541  return color;
542  else
543  return underlinecolor;
544  }
545 
548  underlinecolor = -1.f;
549  }
550 
552  void SetStrike(bool value) {
553  strike = value;
554  }
555 
557  void Strike() {
558  strike = true;
559  }
560 
562  void Strike(RGBAf color) {
563  strike = true;
564  strikecolor = color;
565  }
566 
568  bool GetStrike() const {
569  return strike;
570  }
571 
575  void SetStrikeColor(RGBAf value) {
576  strikecolor = value;
577  }
578 
581  if(strikecolor.R == -1)
582  return color;
583  else
584  return strikecolor;
585  }
586 
589  strikecolor = -1.f;
590  }
591 
595  void SetStrikePosition(int value) {
596  strikepos = value;
597  }
598 
600  int GetStrikePosition() const {
601  if(strikepos == INT_MIN)
602  return (int)std::round( (renderer->GetHeight() - renderer->GetLineThickness()) * .6f );
603  else
604  return strikepos;
605  }
606 
609  defaultalign = value;
610  }
611 
613  void AlignLeft() {
614  defaultalign = TextAlignment::Left;
615  justify = false;
616  }
617 
619  void AlignRight() {
620  defaultalign = TextAlignment::Right;
621  justify = false;
622  }
623 
625  void AlignCenter() {
626  defaultalign = TextAlignment::Center;
627  justify = false;
628  }
629 
632  return defaultalign;
633  }
634 
637  void SetJustify(bool value) {
638  justify = value;
639  }
640 
642  void JustifyLeft() {
643  defaultalign = TextAlignment::Left;
644  justify = true;
645  }
646 
648  void JustifyRight() {
649  defaultalign = TextAlignment::Right;
650  justify = true;
651  }
652 
654  void JustifyCenter() {
655  defaultalign = TextAlignment::Center;
656  justify = true;
657  }
658 
660  bool GetJustify() const {
661  return justify;
662  }
663 
667  void SetLineSpacingPixels(int value) {
668  vspace = (float)value / renderer->GetHeight();
669  }
670 
672  int GetLineSpacingPixels() const {
673  return (int)std::round(vspace * renderer->GetHeight());
674  }
675 
680  void SetLineSpacing(float value) {
681  vspace = value;
682  }
683 
685  float GetLineSpacing() const {
686  return vspace;
687  }
688 
691  void SetLetterSpacing(int value) {
692  hspace = value;
693  }
694 
696  int GetLetterSpacing() const {
697  return hspace;
698  }
699 
703  void SetTabWidth(int value) {
704  tabwidth = value;
705  }
706 
708  void SetTabWidthInLetters(float value) {
709  tabwidth = (int)std::round(value * renderer->GetCursorAdvance('A'));
710  }
711 
713  int GetTabWidth() const {
714  return tabwidth;
715  }
716 
719  void SetParagraphSpacing(int value) {
720  pspace = value;
721  }
722 
724  int GetParagraphSpacing() const {
725  return pspace;
726  }
727 
728  virtual bool IsReady() const override {
729  return renderer != nullptr;
730  }
731 
732  virtual int GetEMSize() const override {
733  return renderer->GetEMSize();
734  }
735 
736  virtual float GetBaseLine() const override {
737  return renderer->GetBaseLine();
738  }
739 
740  virtual int GetHeight() const override {
741  return renderer->GetHeight();
742  }
743 
744  virtual const GlyphRenderer &GetGlyphRenderer() const override {
745  return *renderer;
746  }
747 
748  virtual Geometry::Size GetSize(const std::string &text) const override;
749 
750  virtual Geometry::Size GetSize(const std::string &text, int width) const override;
751 
752  virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const override;
753 
754  virtual Geometry::Rectangle GetPosition(const std::string& text, int index) const override;
755 
756  virtual int GetCharacterIndex(const std::string &text, int w, Geometry::Point location, bool wrap = true) const override;
757 
758  virtual Geometry::Rectangle GetPosition(const std::string &text, int w, int index, bool wrap = true) const override;
759 
760  protected:
761  virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const override;
762 
763  virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override {
764  print(target, text, location, defaultalign);
765  }
766 
767  virtual void printnowrap(TextureTarget &target, const std::string &text,
768  Geometry::Rectangle location, TextAlignment align) const override;
769 
770  virtual void print(TextureTarget &target, const std::string &text,
771  Geometry::Rectangle location, TextAlignment align_override) const override;
772 
773 
774 
775  virtual void printnowrap(TextureTarget &target, const std::string &text,
776  Geometry::Rectangle location) const override {
777  printnowrap(target, text, location, defaultalign);
778  }
779 
780  private:
781  //internal, float to facilitate shadow offset
782  void print(TextureTarget &target, const std::string &text, Geometry::Pointf location, RGBAf color, RGBAf strikecolor, RGBAf underlinecolor) const;
783 
784  void print(TextureTarget &target, const std::string &text, Geometry::Rectanglef location, TextAlignment align, RGBAf color, RGBAf strikecolor, RGBAf underlinecolor) const;
785 
786  GlyphRenderer *renderer = nullptr;
787 
788  RGBAf color = 1.f;
789 
790  TextShadow shadow = {};
791  bool underline = false;
792  RGBAf underlinecolor = -1.f;
793  bool strike = false;
794  RGBAf strikecolor = -1.f;
795  int strikepos = INT_MIN;
796  TextAlignment defaultalign = TextAlignment::Left;
797  bool justify = false;
798  float vspace = 1.0f;
799  int hspace = 0;
800  int pspace = 0;
801  int tabwidth = 0;
802  };
803 
804 } }
Gorgon::Resource::GID::Font_Charmap_II
constexpr Type Font_Charmap_II
Definition: GID.h:205
Gorgon::Geometry::basic_Rectangle::TopLeft
basic_Point< T_ > TopLeft() const
Returns the top left coordinates of the rectangle.
Definition: Rectangle.h:198
Gorgon::Graphics::StyledRenderer::IsReady
virtual bool IsReady() const override
Whether the render can render text.
Definition: Font.h:728
Gorgon::Graphics::TextRenderer::GetBaseLine
virtual float GetBaseLine() const =0
Get the distance of baseline from the top of the text.
Gorgon::Graphics::TextRenderer::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w) const
Definition: Font.h:198
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const
Definition: Font.h:296
Gorgon::swap
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
Gorgon::Resource::GID::Font_BitmapProps
constexpr Type Font_BitmapProps
Definition: GID.h:206
Gorgon::Resource::GID::Font_Charmap
constexpr Type Font_Charmap
Definition: GID.h:200
Gorgon::Graphics::GlyphRenderer::IsFixedWidth
virtual bool IsFixedWidth() const =0
This function should return true if this font is fixed width.
Gorgon::Graphics::StyledRenderer::ResetUnderlineColor
void ResetUnderlineColor()
Sets underline color to match with text color.
Definition: Font.h:547
Gorgon::Graphics::internal::simplelayout
void simplelayout(const GlyphRenderer &renderer, std::string::const_iterator begin, std::string::const_iterator end, std::function< int(Glyph, Glyph)> spacing, std::function< int(Glyph)> advance, std::function< bool(Glyph, int, float)> process, std::function< void()> dotab, std::function< void(Glyph)> donewline)
helps with the simple layouts, decodes and executes unicode instructions.
Definition: Font.cpp:275
Gorgon::String::From
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
Gorgon::Graphics::StyledRenderer::SetDefaultAlign
void SetDefaultAlign(TextAlignment value)
Sets the default alignment for the text.
Definition: Font.h:608
Gorgon::Graphics::TextRenderer::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const =0
Should print the given text to the specified location and color.
Gorgon::Graphics::StyledRenderer::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const override
Definition: Font.cpp:992
Gorgon::Resource::Font::save
void save(Writer &writer) const override
Definition: Font.cpp:41
Gorgon::Graphics::BasicFont::SetColor
void SetColor(RGBAf value)
Changes the the color of the text. Color can only be overridden through BasicFont interface.
Definition: Font.h:335
Gorgon::Graphics::BasicFont::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
Should print the given text to the specified location and color.
Definition: Font.h:409
File.h
Gorgon::Graphics::internal::isspaced
bool isspaced(Glyph g)
Definition: Font.cpp:75
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const
Definition: Font.h:304
Gorgon::Resource::Writer::GetStream
std::ostream & GetStream()
This should be last resort, use if the actual stream is needed.
Definition: Writer.h:96
Gorgon::Graphics::GlyphRenderer::IsASCII
virtual bool IsASCII() const =0
This function should return true if this font renderer supports only 7-bit ASCII.
Gorgon::Graphics::StyledRenderer::GetLetterSpacing
int GetLetterSpacing() const
Returns the spacing between the letters in pixels.
Definition: Font.h:696
Gorgon::Graphics::StyledRenderer::SetLineSpacingPixels
void SetLineSpacingPixels(int value)
Sets the line spacing in pixels, this spacing is the space between two lines, from the descender of t...
Definition: Font.h:667
TextureTargets.h
Gorgon::Graphics::GlyphRenderer::GetBaseLine
virtual float GetBaseLine() const =0
Baseline point of glyphs from the top.
Gorgon::Graphics::GlyphRenderer::GetCursorAdvance
virtual float GetCursorAdvance(Glyph g) const =0
This function should return the number of pixels the cursor should advance after this glyph.
Gorgon::Graphics::StyledRenderer::GetParagraphSpacing
int GetParagraphSpacing() const
Get the space between paragraphs in pixels.
Definition: Font.h:724
Gorgon::Graphics::GlyphRenderer::Prepare
virtual void Prepare(const std::string &) const
Notifies glyph renderer about a text to be rendered.
Definition: Font.h:143
Gorgon::Containers::Collection::Add
bool Add(T_ *Data)
Adds the given item to the end of the list if it is not already in the list.
Definition: Collection.h:248
Gorgon::Graphics::TextRenderer::IsReady
virtual bool IsReady() const =0
Whether the render can render text.
Gorgon::Graphics::StyledRenderer::SetUnderline
void SetUnderline(bool value)
Sets underlining for the text.
Definition: Font.h:511
Gorgon::Geometry::basic_Point::X
T_ X
X coordinate.
Definition: Point.h:368
Gorgon::Graphics::TextRenderer::GetCharacterIndex
virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const =0
Returns the character index of glyph immediately after the given location. This function is Unicode a...
Gorgon::Graphics::StyledRenderer::StyledRenderer
StyledRenderer(GlyphRenderer &renderer, RGBAf color=1.f, TextShadow shadow={})
Renderer must be ready in order to calculate spacings correctly.
Definition: Font.h:465
Gorgon::Resource::Font::SetRenderer
void SetRenderer(Graphics::GlyphRenderer &renderer)
Changes the renderer to the given renderer.
Definition: Font.cpp:14
Gorgon::Graphics::StyledRenderer::GetDefaultAlign
TextAlignment GetDefaultAlign() const
Returns the default alignment for the text.
Definition: Font.h:631
Gorgon::Graphics::GlyphRenderer::GetEMSize
virtual int GetEMSize() const =0
Returns the size of the EM dash.
Gorgon::Graphics::StyledRenderer::Underline
void Underline(RGBAf color)
Underlines the text with the given color.
Definition: Font.h:521
Gorgon::Geometry::basic_Rectangle::X
T_ X
X coordinate of the top left corner of this rectangle.
Definition: Rectangle.h:354
Gorgon::Resource::Writer::WriteChunkHeader
void WriteChunkHeader(GID::Type type, unsigned long size)
Writes the header of a chunk.
Definition: Writer.h:364
Gorgon::Resource::Image::SaveThis
static void SaveThis(Writer &writer, const Graphics::Bitmap &bmp, GID::Type type=GID::Image)
This function can be used to save a bitmap as image resource without modifying it.
Definition: Image.cpp:171
Gorgon::Resource::Writer::WritePointf
void WritePointf(Geometry::Pointf value)
Writes a point to the stream, point takes 2 x 4 bytes.
Definition: Writer.h:251
Gorgon::Graphics::TextRenderer::GetSize
virtual Geometry::Size GetSize(const std::string &text, int width) const =0
Returns the size of the given text.
Gorgon::Graphics::BitmapFont::Pack
void Pack(bool tight=false, DeleteConstants del=Owned)
Converts individual glyphs to a single atlas.
Definition: BitmapFont.cpp:920
Gorgon::Graphics::StyledRenderer::SetTabWidthInLetters
void SetTabWidthInLetters(float value)
Sets the tab width in digit widths.
Definition: Font.h:708
Gorgon::Graphics::internal::dodefaulttab
void dodefaulttab(T_ s, T_ &x, T_ w)
Definition: Font.cpp:196
Gorgon::Graphics::StyledRenderer::GetShadow
TextShadow GetShadow() const
Returns text shadow.
Definition: Font.h:506
Gorgon::Graphics::BasicFont::GetCharacterIndex
virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const override
Returns the character index of glyph immediately after the given location. This function is Unicode a...
Definition: Font.cpp:720
Gorgon::begin
std::vector< T_ >::const_iterator begin(enum_type_id< T_ >)
Definition: Enum.h:283
Gorgon::Graphics::BitmapFont::SetLineGap
void SetLineGap(float value)
Changes the distance between two lines. Non-integer values are not recommended.
Definition: BitmapFont.h:263
Gorgon::Graphics::internal::isbreaking
bool isbreaking(Glyph g)
Definition: Font.cpp:129
Gorgon::Graphics::internal::isnewline
bool isnewline(Glyph g)
Definition: Font.cpp:79
Gorgon::Graphics::GlyphRenderer::GetSize
virtual Geometry::Size GetSize(Glyph chr) const =0
This function should return the size of the requested glyph.
Gorgon::Resource::Base::Prepare
virtual void Prepare()
This function shall prepare this resource to be used after resource is loaded.
Definition: Base.cpp:16
Gorgon::Graphics::internal::markvecit
std::vector< glyphmark >::iterator markvecit
Definition: Font.cpp:355
Gorgon::Graphics::internal::rounddiv
int rounddiv(int v, float f)
Definition: Font.h:58
Gorgon::Containers::Collection::GetSize
long GetSize() const
Returns number of elements.
Definition: Collection.h:241
Gorgon::Graphics::StyledRenderer::SetParagraphSpacing
void SetParagraphSpacing(int value)
Changes the additional space between paragraphs.
Definition: Font.h:719
Gorgon::Graphics::GlyphRange::End
Glyph End
End point of the range. This value is included in the range.
Definition: Font.h:42
Gorgon::Graphics::TextAlignment::Left
@ Left
Text is aligned to left.
Gorgon::Resource::Reader::ReadArray
void ReadArray(T_ *data, unsigned long size)
Reads an array from the file.
Definition: Reader.h:333
Gorgon::Graphics::StyledRenderer::GetStrike
bool GetStrike() const
Returns whether the text would stroked.
Definition: Font.h:568
Gorgon::Graphics::BasicFont::BasicFont
BasicFont(const GlyphRenderer &renderer, RGBAf color=1.f, TextAlignment defaultalign=TextAlignment::Left)
Definition: Font.h:273
Gorgon::Graphics::StyledRenderer::GetPosition
virtual Geometry::Rectangle GetPosition(const std::string &text, int index) const override
Returns the position of the glyph at the character index.
Definition: Font.cpp:1130
Gorgon::Graphics::StyledRenderer::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
Should print the given text to the specified location and color.
Definition: Font.h:775
Gorgon::Resource::GID::Font_FreeTypeProps
constexpr Type Font_FreeTypeProps
Definition: GID.h:208
Gorgon::Graphics::GlyphRenderer::GetLineGap
virtual float GetLineGap() const =0
This is the default distance between two consecutive lines.
Gorgon::Graphics::GlyphRenderer
Should be implemented by the systems aimed to render fonts on the screen.
Definition: Font.h:67
Gorgon::Graphics::RGBAf
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
Gorgon::Graphics::StyledRenderer::UseFlatShadow
void UseFlatShadow(RGBAf color, Geometry::Pointf offset={1.f, 1.f})
Uses flat shadow for text.
Definition: Font.h:501
Gorgon::Resource::GID::Image
constexpr Type Image
Image resource.
Definition: GID.h:149
Gorgon::Resource::Writer::WriteObjectStart
Marker WriteObjectStart(const Base &base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: File.cpp:211
Gorgon::Graphics::BasicFont::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const
Definition: Font.h:320
Gorgon::Graphics::BasicFont::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location, RGBAf color) const
Definition: Font.h:414
Gorgon::Graphics::StyledRenderer::SetShadow
void SetShadow(TextShadow value)
Changes text shadow.
Definition: Font.h:491
Gorgon::Geometry::basic_Rectangle::Width
T_ Width
Width of the rectangle.
Definition: Rectangle.h:360
Gorgon::Graphics::TextShadow
Describes how a text shadow should be.
Definition: Font.h:432
Gorgon::Graphics::StyledRenderer::GetTabWidth
int GetTabWidth() const
Returns tab width in pixels.
Definition: Font.h:713
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, RGBAf color) const
Definition: Font.h:280
Gorgon::Graphics::GlyphRenderer::NeedsPrepare
virtual bool NeedsPrepare() const
Should return if the glyph renderer requires preparation regarding the text given.
Definition: Font.h:139
Gorgon::Graphics::internal::boundedprint
void boundedprint(const GlyphRenderer &renderer, std::string::const_iterator begin, std::string::const_iterator end, int width, std::function< void(Glyph, markvecit, markvecit, int)> doline, std::function< int(Glyph, Glyph)> spacing, std::function< int(Glyph)> advance, std::function< void(int &)> dotab)
Definition: Font.cpp:357
Gorgon::Graphics::StyledRenderer::DisableShadow
void DisableShadow()
Disables text shadow.
Definition: Font.h:496
Gorgon::Graphics::internal::defaultspace
float defaultspace(Glyph g, const GlyphRenderer &renderer)
Definition: Font.cpp:145
Gorgon::Resource::Writer::WriteUInt32
void WriteUInt32(unsigned long value)
Writes a 32-bit unsigned integer to the stream.
Definition: Writer.h:158
Gorgon::Graphics::TextAlignment::Right
@ Right
Text is aligned to right.
Font.h
Gorgon::Resource::Font::data
Graphics::GlyphRenderer * data
Definition: Font.h:89
Gorgon::Graphics::BasicFont::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const
Definition: Font.h:308
Gorgon::Utils::ASSERT_FALSE
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
Color.h
Gorgon::Graphics::internal::decode
Glyph decode(std::string::const_iterator &it, std::string::const_iterator end)
Decodes a utf-8 character from the given iterator.
Definition: Font.cpp:9
Gorgon::Graphics::BasicFont::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const
Definition: Font.h:312
Gorgon::Graphics::TextRenderer::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const =0
Gorgon::Resource::Reader::ReadFloat
float ReadFloat()
Reads a 32 bit IEEE floating point number from the file.
Definition: Reader.h:271
Gorgon::Graphics::StyledRenderer::AlignRight
void AlignRight()
Aligns the text to the right, removes justify.
Definition: Font.h:619
Gorgon::Resource::Reader::ReadInt32
long ReadInt32()
Reads a 32-bit integer from the stream.
Definition: Reader.h:217
Gorgon::Graphics::FreeType::LoadGlyphs
bool LoadGlyphs(GlyphRange range, bool prepare=true)
Loads the glyphs in the given range.
Definition: FreeType.cpp:1058
Gorgon::Graphics::StyledRenderer::GetHeight
virtual int GetHeight() const override
Get the distance of baseline from the top of the text.
Definition: Font.h:740
Gorgon::Resource::Font::Discard
virtual void Discard() override
This function shall discard any transitional data which is not vital after Prepare function is issued...
Definition: Font.cpp:252
Gorgon::Graphics::TextRenderer::GetGlyphRenderer
virtual const GlyphRenderer & GetGlyphRenderer() const =0
Returns the glyphrenderer that is used by this text renderer.
Gorgon::Resource::Font::Prepare
virtual void Prepare() override
This function will only prepare images loaded from a resource, does not work for images loaded later.
Definition: Font.cpp:245
Gorgon::Graphics::internal::isspace
bool isspace(Glyph g)
Definition: Font.cpp:96
Gorgon::Graphics::BasicFont::GetEMSize
virtual int GetEMSize() const override
Returns the size of the EM dash.
Definition: Font.h:352
Gorgon::Graphics::BasicFont::GetDefaultAlignment
TextAlignment GetDefaultAlignment() const
Returns the current default alignment.
Definition: Font.h:330
Gorgon::Graphics::GlyphRange::Count
int Count() const
Returns the number of the glyphs in the range.
Definition: Font.h:27
Gorgon::Graphics::StyledRenderer::GetGlyphRenderer
GlyphRenderer & GetGlyphRenderer()
Definition: Font.h:472
Gorgon::Graphics::StyledRenderer::GetStrikePosition
int GetStrikePosition() const
Returns current strike position.
Definition: Font.h:600
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Graphics::GlyphRange::Start
Glyph Start
Start point of the range.
Definition: Font.h:39
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::Graphics::TextRenderer::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align_override) const =0
Should print the given text to the specified location and color.
Gorgon::Graphics::BitmapFont::SetUnderlineOffset
void SetUnderlineOffset(int value)
Changes the underline position to the specified value.
Definition: BitmapFont.h:257
Gorgon::Char
uint32_t Char
Definition: Types.h:46
Gorgon::Resource::GID::Font_BitmapKerning
constexpr Type Font_BitmapKerning
Definition: GID.h:207
Gorgon::Graphics::internal::simpleprint
void simpleprint(const GlyphRenderer &renderer, std::string::const_iterator begin, std::string::const_iterator end, std::function< int(Glyph, Glyph)> spacing, std::function< int(Glyph)> advance, std::function< void(Glyph, int, float)> render, std::function< void()> dotab, std::function< void(Glyph)> donewline)
helps with the simple layouts, decodes and executes unicode instructions.
Definition: Font.cpp:207
Gorgon::Resource::Writer::WriteChunkStart
Marker WriteChunkStart(GID::Type type)
Writes the start of a chunk. Should have a matching WriteEnd.
Definition: Writer.h:351
Gorgon::Graphics::BasicFont::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
Definition: Font.h:399
Gorgon::Graphics::RGBAf::R
float R
Red channel.
Definition: Color.h:588
Gorgon::Graphics::StyledRenderer::SetLetterSpacing
void SetLetterSpacing(int value)
Spacing between letters of the text, in pixels.
Definition: Font.h:691
Gorgon::Graphics::BasicFont::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align, RGBAf color) const
Definition: Font.cpp:1600
Gorgon::Graphics::Bitmap::HasData
bool HasData() const
Checks if this image resource has a data attached to it.
Definition: Bitmap.h:163
Gorgon::Resource::Reader::ReadUInt32
unsigned long ReadUInt32()
Reads a 32-bit unsigned integer from the stream.
Definition: Reader.h:226
Gorgon::Graphics::TextureTarget::GetTargetSize
virtual Geometry::Size GetTargetSize() const =0
Get size of the target.
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const
Definition: Font.h:300
Gorgon::Graphics::StyledRenderer::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
Should print the given text to the specified location and color.
Definition: Font.cpp:1619
Gorgon::Graphics::TextShadow::type
ShadowType type
Definition: Font.h:450
Gorgon::Graphics::GlyphRenderer::GetDigitWidth
virtual int GetDigitWidth() const =0
Width of a digit, if digits do not have the same width, maximum should be returned.
Gorgon::Graphics::TextRenderer::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
Definition: Font.h:194
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, Geometry::Point location, RGBAf color) const
Definition: Font.h:284
Gorgon::Resource::Font::isowner
bool isowner
Definition: Font.h:93
Gorgon::Graphics::StyledRenderer::GetLineSpacingPixels
int GetLineSpacingPixels() const
Returns the line spacing in pixels.
Definition: Font.h:672
ASSERT
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Gorgon::Resource::Reader::ReadChunkSize
unsigned long ReadChunkSize()
Reads chunk size from a stream.
Definition: Reader.h:381
Gorgon::Graphics::StyledRenderer::JustifyCenter
void JustifyCenter()
Aligns the text to the center, sets justify.
Definition: Font.h:654
Gorgon::Graphics::StyledRenderer::Strike
void Strike()
Strikes the text.
Definition: Font.h:557
Gorgon::Containers::Collection
Collection is a container for reference typed objects.
Definition: Collection.h:21
Gorgon::Geometry::Point
basic_Point< int > Point
Definition: Point.h:598
Gorgon::Graphics::StyledRenderer::GetEMSize
virtual int GetEMSize() const override
Returns the size of the EM dash.
Definition: Font.h:732
Gorgon::Graphics::BasicFont::GetBaseLine
virtual float GetBaseLine() const override
Get the distance of baseline from the top of the text.
Definition: Font.h:356
Gorgon::Graphics::TextAlignment::Center
@ Center
Text is aligned to center.
Gorgon::Graphics::TextShadow::ShadowType
ShadowType
Definition: Font.h:435
Gorgon::Graphics::TextAlignment
TextAlignment
Defines how a text is aligned.
Definition: Graphics.h:67
Gorgon::Graphics::Glyph
Gorgon::Char Glyph
Glyph is a symbol for a character. In Gorgon, glyphs are UTF32 chars.
Definition: Font.h:15
Gorgon::Graphics::GlyphRenderer::GetUnderlineOffset
virtual int GetUnderlineOffset() const =0
The position of the underline, if it is to be drawn.
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::Graphics::GlyphRange::Normalize
void Normalize()
Definition: Font.h:33
Gorgon::Graphics::BasicFont::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
Should print the given text to the specified location and color.
Definition: Font.h:381
Gorgon::Resource::Font::LoadResource
static Font * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a bitmap font resource from the given file.
Definition: Font.cpp:116
Gorgon::Graphics::TextRenderer::GetSize
virtual Geometry::Size GetSize(const std::string &text) const =0
Returns the size of the given text.
Gorgon::Graphics::BitmapFont::SetHeight
void SetHeight(int value)
Changes the line height of the font. Adding glyphs may override this value.
Definition: BitmapFont.h:237
Gorgon::Graphics::StyledRenderer::GetStrikeColor
RGBAf GetStrikeColor() const
Returns the current strike color.
Definition: Font.h:580
Gorgon::Graphics::BitmapFont::SetGlyphSpacing
void SetGlyphSpacing(int value)
Changes the spacing between glyphs.
Definition: BitmapFont.h:248
Gorgon::Graphics::TextRenderer::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
Definition: Font.h:190
Gorgon::Graphics::StyledRenderer::AlignLeft
void AlignLeft()
Aligns the text to the left, removes justify.
Definition: Font.h:613
Gorgon::Graphics::StyledRenderer::SetUnderlineColor
void SetUnderlineColor(RGBAf value)
Changes the underline color of the text.
Definition: Font.h:534
Gorgon::Resource::Reader::Target
Mark Target(unsigned long delta)
Creates mark to the the target that is delta distance from current point in file.
Definition: Reader.h:193
Gorgon::Resource::Reader::EatChunk
void EatChunk(long size)
Removes a chunk of data with the given size from the stream.
Definition: Reader.h:389
Gorgon::Graphics::TextRenderer::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
Definition: Font.h:186
Gorgon::Graphics::BasicFont::PrintNoWrap
void PrintNoWrap(TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const
Definition: Font.h:316
Gorgon::Graphics::TextureTarget
This interface defines a class that can be used as a common target for texture based drawing.
Definition: TextureTargets.h:12
Gorgon::Graphics::TextRenderer::GetCharacterIndex
virtual int GetCharacterIndex(const std::string &text, int w, Geometry::Point location, bool wrap=true) const =0
Returns the character index of glyph immediately after the given location. This function is Unicode a...
Gorgon::Graphics::TextShadow::Flat
@ Flat
Definition: Font.h:437
Gorgon::Graphics::GlyphRenderer::Exists
virtual bool Exists(Glyph g) const =0
Returns true if the glyph exists.
Gorgon::Graphics::internal::isadjustablespace
bool isadjustablespace(Glyph g)
Definition: Font.cpp:115
Gorgon::Graphics::BasicFont::GetGlyphRenderer
virtual const GlyphRenderer & GetGlyphRenderer() const override
Returns the glyphrenderer that is used by this text renderer.
Definition: Font.h:348
Gorgon::Graphics::BasicFont::IsReady
virtual bool IsReady() const override
Whether the render can render text.
Definition: Font.h:344
Gorgon::Graphics::StyledRenderer::SetTabWidth
void SetTabWidth(int value)
Distance between tab stops.
Definition: Font.h:703
Gorgon::Graphics::TextRenderer::GetEMSize
virtual int GetEMSize() const =0
Returns the size of the EM dash.
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::Graphics::StyledRenderer::SetGlyphRenderer
void SetGlyphRenderer(GlyphRenderer &renderer)
Definition: Font.h:476
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Graphics::TextureTarget::Draw
virtual void Draw(const TextureSource &image, const Geometry::Pointf &p1, const Geometry::Pointf &p2, const Geometry::Pointf &p3, const Geometry::Pointf &p4, RGBAf color=RGBAf(1.f))=0
Draws a simple texture to the screen.
Gorgon::Graphics::TextRenderer::GetHeight
virtual int GetHeight() const =0
Get the distance of baseline from the top of the text.
Gorgon::Graphics::GlyphRange::GlyphRange
GlyphRange(Glyph start, Glyph end)
Definition: Font.h:24
Gorgon::Graphics::TextRenderer
This class allows printing text on the screen.
Definition: Font.h:152
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const
Definition: Font.h:292
Gorgon::Graphics::BitmapFont::GlyphDescriptor
to be used internally.
Definition: BitmapFont.h:28
Gorgon::Graphics::TextRenderer::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const =0
Gorgon::Graphics::TextShadow::TextShadow
TextShadow()=default
Gorgon::Resource::Reader::ReadGID
GID::Type ReadGID()
Reads a GID from the given stream.
Definition: Reader.h:341
Gorgon::Graphics::GlyphRenderer::Render
virtual void Render(Glyph chr, TextureTarget &target, Geometry::Pointf location, RGBAf color) const =0
This function should render the given character to the target at the specified location and color.
Gorgon::Graphics::TextRenderer::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align_override) const =0
Should print the given text to the specified location and color.
Gorgon::Graphics::StyledRenderer::SetLineSpacing
void SetLineSpacing(float value)
Sets the line spacing as percentage of line gap.
Definition: Font.h:680
Gorgon::Byte
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Gorgon::Graphics::TextShadow::None
@ None
Definition: Font.h:436
Gorgon::Graphics::StyledRenderer::GetJustify
bool GetJustify() const
Returns whether the text would be justified.
Definition: Font.h:660
Gorgon::Resource::Writer::WriteEnd
void WriteEnd(Marker &marker)
This function performs writes necessary to end a chunk that is represented by the marker.
Definition: Writer.h:373
Gorgon::Graphics::BasicFont
This is the basic font, performing the minimal amount of operations necessary to render text on the s...
Definition: Font.h:271
Gorgon::Geometry::basic_Rectangle::Y
T_ Y
Y coordinate of the top left corner of this rectangle.
Definition: Rectangle.h:357
Gorgon::Graphics::StyledRenderer::StyledRenderer
StyledRenderer()=default
Gorgon::Graphics::StyledRenderer::GetBaseLine
virtual float GetBaseLine() const override
Get the distance of baseline from the top of the text.
Definition: Font.h:736
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Graphics::FreeType::LoadMetrics
bool LoadMetrics(int size)
Continues loading a file by setting font size and obtaining necessary information.
Definition: FreeType.cpp:314
Gorgon::Geometry::basic_Rectangle::Height
T_ Height
Height of the rectangle.
Definition: Rectangle.h:363
Gorgon::Graphics::StyledRenderer::GetLineSpacing
float GetLineSpacing() const
Returns the line spacing as percentage of line gap.
Definition: Font.h:685
Gorgon::Graphics::BasicFont::GetSize
virtual Geometry::Size GetSize(const std::string &text) const override
Returns the size of the given text.
Definition: Font.cpp:678
Gorgon::Graphics::BitmapFont::GetLineGap
virtual float GetLineGap() const override
This is the default distance between two consecutive lines.
Definition: BitmapFont.h:228
Gorgon::Graphics::FreeType::Assume
bool Assume(std::vector< Byte > &data)
Loads the given data.
Definition: FreeType.cpp:248
Gorgon::Graphics::TextRenderer::~TextRenderer
virtual ~TextRenderer()
Definition: Font.h:154
Gorgon::Resource::GID::Font_Image
constexpr Type Font_Image
Definition: GID.h:203
Gorgon::Resource::Font::tobeprepared
Containers::Collection< Image > tobeprepared
Definition: Font.h:91
Gorgon::Resource::GID::Font_FreeTypeData
constexpr Type Font_FreeTypeData
Definition: GID.h:209
Gorgon::Graphics::BasicFont::defaultalign
TextAlignment defaultalign
Default alignment if none is specified.
Definition: Font.h:420
Gorgon::Geometry::basic_Point::Y
T_ Y
Y coordinate.
Definition: Point.h:371
Gorgon::Resource::Writer::WriteInt32
void WriteInt32(long value)
Writes a 32-bit integer to the stream.
Definition: Writer.h:149
Gorgon::Graphics::BitmapFont
Bitmap fonts provide an easy way to render text on the screen.
Definition: BitmapFont.h:24
Gorgon::Graphics::StyledRenderer::SetColor
void SetColor(RGBAf value)
Changes the color of the text.
Definition: Font.h:481
Gorgon::Graphics::StyledRenderer::GetGlyphRenderer
virtual const GlyphRenderer & GetGlyphRenderer() const override
Returns the glyphrenderer that is used by this text renderer.
Definition: Font.h:744
Gorgon::Graphics::BitmapFont::AssumeGlyph
void AssumeGlyph(Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
Adds a new glyph bitmap to the list.
Definition: BitmapFont.h:164
Gorgon::Graphics::GlyphRange
This class represents a range of glyphs. Both start and end is included.
Definition: Font.h:18
Gorgon::Graphics::internal::boundedlayout
void boundedlayout(const GlyphRenderer &renderer, std::string::const_iterator begin, std::string::const_iterator end, int width, std::function< bool(Glyph, markvecit, markvecit, int, int)> doline, std::function< int(Glyph, Glyph)> spacing, std::function< int(Glyph)> advance, std::function< void(int &)> dotab)
Definition: Font.cpp:503
Gorgon::Graphics::GlyphRenderer::GetMaxWidth
virtual int GetMaxWidth() const =0
Returns the width of widest glyph.
Gorgon::end
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
Gorgon::Graphics::BasicFont::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location, RGBAf color) const
Definition: Font.h:404
Gorgon::Graphics::BasicFont::Print
void Print(TextureTarget &target, const std::string &text, int x, int y, RGBAf color) const
Definition: Font.h:288
Gorgon::Graphics::TextShadow::TextShadow
TextShadow(ShadowType type)
Definition: Font.h:442
Gorgon::Input::Keyboard::Keycodes::Right
constexpr Key Right
Definition: Keyboard.h:64
Gorgon::Graphics::StyledRenderer::GetSize
virtual Geometry::Size GetSize(const std::string &text) const override
Returns the size of the given text.
Definition: Font.cpp:1036
Gorgon::Graphics::StyledRenderer::ResetStrikeColor
void ResetStrikeColor()
Sets strike color to match with text color.
Definition: Font.h:588
Gorgon::Graphics::StyledRenderer::JustifyLeft
void JustifyLeft()
Aligns the text to the left, sets justify.
Definition: Font.h:642
Gorgon::Graphics::GlyphRenderer::GetHeight
virtual int GetHeight() const =0
Height of glyphs, actual size could be smaller but all glyphs should have the same virtual height.
Gorgon::Graphics::StyledRenderer::SetStrike
void SetStrike(bool value)
Sets whether the text would be stroked.
Definition: Font.h:552
Gorgon::Graphics::BasicFont::GetColor
RGBAf GetColor() const
Returns the current text color.
Definition: Font.h:340
Gorgon::Graphics::StyledRenderer::GetUnderline
bool GetUnderline() const
Returns whether the text is underlined.
Definition: Font.h:527
Gorgon::Resource::Font
Font resource.
Definition: Font.h:16
Gorgon::Graphics::BitmapFont::SetKerning
void SetKerning(Glyph left, Glyph right, Geometry::Pointf kern)
Definition: BitmapFont.h:180
Gorgon::Resource::Reader::ReadPointf
Geometry::Point ReadPointf()
Reads a Pointf from the given stream.
Definition: Reader.h:365
Gorgon::Graphics::StyledRenderer::GetCharacterIndex
virtual int GetCharacterIndex(const std::string &text, Geometry::Point location) const override
Returns the character index of glyph immediately after the given location. This function is Unicode a...
Definition: Font.cpp:1087
Gorgon::Containers::Collection::Push
bool Push(T_ *Data)
Adds the given item to the end of the list if it is not already in the list.
Definition: Collection.h:266
Gorgon::Graphics::StyledRenderer::AlignCenter
void AlignCenter()
Aligns the text to the center, removes justify.
Definition: Font.h:625
Gorgon::Resource::GID::Font_Props
constexpr Type Font_Props
Definition: GID.h:204
Gorgon::Resource::Image::LoadResource
static Image * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a image resource from the given file.
Definition: Image.cpp:9
Gorgon::Graphics::BasicFont::GetHeight
virtual int GetHeight() const override
Get the distance of baseline from the top of the text.
Definition: Font.h:360
Gorgon::Graphics::TextRenderer::Print
void Print(TextureTarget &target, const std::string &text, Geometry::Pointf location) const
Prints the given text to the target.
Definition: Font.h:158
Gorgon::Graphics::TextShadow::TextShadow
TextShadow(RGBAf color, Geometry::Pointf offset={1.f, 1.f})
Definition: Font.h:447
Gorgon::Graphics::StyledRenderer
This text renderer can style text according to the set parameters.
Definition: Font.h:461
Gorgon::Geometry::basic_Rectangle
Represents a rectangle in a 2D space.
Definition: Rectangle.h:19
Gorgon::Graphics::BasicFont::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Point location) const override
Definition: Font.h:377
Gorgon::Graphics::StyledRenderer::print
virtual void print(TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
Definition: Font.h:763
Gorgon::Graphics::TextShadow::TextShadow
TextShadow(ShadowType type, RGBAf color, Geometry::Pointf offset)
Definition: Font.h:444
Gorgon::Graphics::StyledRenderer::GetUnderlineColor
RGBAf GetUnderlineColor() const
Returns the current underline color.
Definition: Font.h:539
Gorgon::Graphics::BitmapFont::SetBaseline
void SetBaseline(float value)
Changes the baseline. Might cause problems if the font already has glyphs in it.
Definition: BitmapFont.h:260
Gorgon::Graphics::GlyphRenderer::KerningDistance
virtual Geometry::Pointf KerningDistance(Glyph left, Glyph right) const =0
This function should return the additional distance between given glyphs.
Gorgon::Graphics::BitmapFont::SetMaxWidth
void SetMaxWidth(int value)
Changes the maximum width for a character. Adding glyphs may override this value.
Definition: BitmapFont.h:240
Gorgon::Graphics::GlyphRenderer::~GlyphRenderer
virtual ~GlyphRenderer()
Definition: Font.h:69
Gorgon::Graphics::StyledRenderer::GetColor
RGBAf GetColor() const
Returns color of the text.
Definition: Font.h:486
Gorgon::Resource::Reader::ReadCommonChunk
bool ReadCommonChunk(Base &self, GID::Type gid, unsigned long size)
Definition: File.cpp:41
Gorgon::Containers::Collection::FindLocation
long FindLocation(const T_ *item) const
Searches the position of a given item, if not found -1 is returned.
Definition: Collection.h:538
Gorgon::Graphics::BasicFont::GetPosition
virtual Geometry::Rectangle GetPosition(const std::string &text, int index) const override
Returns the position of the glyph at the character index.
Definition: Font.cpp:827
Gorgon::Graphics::TextRenderer::GetPosition
virtual Geometry::Rectangle GetPosition(const std::string &text, int w, int index, bool wrap=true) const =0
Returns the position of the glyph at the character index.
Gorgon::Graphics::StyledRenderer::Underline
void Underline()
Underlines the text.
Definition: Font.h:516
Gorgon::Input::Keyboard::Keycodes::Left
constexpr Key Left
Definition: Keyboard.h:62
Gorgon::Graphics::TextRenderer::GetPosition
virtual Geometry::Rectangle GetPosition(const std::string &text, int index) const =0
Returns the position of the glyph at the character index.
Gorgon::Resource::Font::Font
Font()
Definition: Font.h:18
Gorgon::Graphics::BitmapFont::SetLineThickness
void SetLineThickness(int value)
Changes the line thickness to the specified value.
Definition: BitmapFont.h:254
Gorgon::Graphics::FreeType
This class allows using font files for text rendering.
Definition: FreeType.h:49
Gorgon::Graphics::BitmapFont::GetBaseLine
virtual float GetBaseLine() const override
Baseline point of glyphs from the top.
Definition: BitmapFont.h:226
Gorgon::Graphics::TextShadow::color
RGBAf color
Definition: Font.h:451
Gorgon::Graphics::StyledRenderer::SetStrikePosition
void SetStrikePosition(int value)
Changes the strike position to the given value.
Definition: Font.h:595
Gorgon::Graphics::internal::ceildiv
int ceildiv(int v, float f)
Definition: Font.h:57
Gorgon::Graphics::BasicFont::printnowrap
virtual void printnowrap(TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
Should print the given text to the specified location and color.
Definition: Font.h:394
Gorgon::Graphics::StyledRenderer::Strike
void Strike(RGBAf color)
Strikes the text with the given color.
Definition: Font.h:562
Gorgon::Graphics::BasicFont::color
RGBAf color
Color of this renderer, can be overridden.
Definition: Font.h:423
Gorgon::Graphics::StyledRenderer::JustifyRight
void JustifyRight()
Aligns the text to the right, sets justify.
Definition: Font.h:648
Gorgon::Resource::Writer::WriteFloat
void WriteFloat(float value)
Writes a 32 bit IEEE floating point number to the file.
Definition: Writer.h:203
Assert.h
Gorgon::Graphics::StyledRenderer::SetJustify
void SetJustify(bool value)
Sets whether the text would be justified.
Definition: Font.h:637
Gorgon::Graphics::GlyphRenderer::GetLineThickness
virtual float GetLineThickness() const =0
Should return the average thickness of a line.
Gorgon::Graphics::BasicFont::SetDefaultAlignment
void SetDefaultAlignment(TextAlignment value)
Changes the default alignment. It is possible to override default alignment through TextRenderer inte...
Definition: Font.h:325
Gorgon::Graphics::GlyphRenderer::GetLetterHeight
virtual std::pair< int, int > GetLetterHeight(bool asciionly=false) const =0
Returns the offset (first) and maximum height (second) that is used by letters.
Gorgon::Graphics::StyledRenderer::SetStrikeColor
void SetStrikeColor(RGBAf value)
Changes the strike color of the text.
Definition: Font.h:575
Gorgon::Graphics::GlyphRange::GlyphRange
GlyphRange(Glyph value=0xFFFF)
Creates a range that includes a single item.
Definition: Font.h:22
Gorgon::Graphics::TextShadow::offset
Geometry::Pointf offset
Definition: Font.h:452