agg_gsv_text.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // Permission to copy, use, modify, sell and distribute this software
  6. // is granted provided this copyright notice appears in all copies.
  7. // This software is provided "as is" without express or implied
  8. // warranty, and with no claim as to its suitability for any purpose.
  9. //
  10. //----------------------------------------------------------------------------
  11. // Contact: mcseem@antigrain.com
  12. // mcseemagg@yahoo.com
  13. // http://www.antigrain.com
  14. //----------------------------------------------------------------------------
  15. //
  16. // Class gsv_text
  17. //
  18. //----------------------------------------------------------------------------
  19. #ifndef AGG_GSV_TEXT_INCLUDED
  20. #define AGG_GSV_TEXT_INCLUDED
  21. #include "agg_array.h"
  22. #include "agg_conv_stroke.h"
  23. #include "agg_conv_transform.h"
  24. namespace agg
  25. {
  26. //---------------------------------------------------------------gsv_text
  27. //
  28. // See Implementation agg_gsv_text.cpp
  29. //
  30. class gsv_text
  31. {
  32. enum status
  33. {
  34. initial,
  35. next_char,
  36. start_glyph,
  37. glyph
  38. };
  39. public:
  40. gsv_text();
  41. void font(const void* font);
  42. void flip(bool flip_y) { m_flip = flip_y; }
  43. void load_font(const char* file);
  44. void size(double height, double width=0.0);
  45. void space(double space);
  46. void line_space(double line_space);
  47. void start_point(double x, double y);
  48. void text(const char* text);
  49. double text_width();
  50. void rewind(unsigned path_id);
  51. unsigned vertex(double* x, double* y);
  52. private:
  53. // not supposed to be copied
  54. gsv_text(const gsv_text&);
  55. const gsv_text& operator = (const gsv_text&);
  56. int16u value(const int8u* p) const
  57. {
  58. int16u v;
  59. if(m_big_endian)
  60. {
  61. *(int8u*)&v = p[1];
  62. *((int8u*)&v + 1) = p[0];
  63. }
  64. else
  65. {
  66. *(int8u*)&v = p[0];
  67. *((int8u*)&v + 1) = p[1];
  68. }
  69. return v;
  70. }
  71. private:
  72. double m_x;
  73. double m_y;
  74. double m_start_x;
  75. double m_width;
  76. double m_height;
  77. double m_space;
  78. double m_line_space;
  79. char m_chr[2];
  80. char* m_text;
  81. pod_array<char> m_text_buf;
  82. char* m_cur_chr;
  83. const void* m_font;
  84. pod_array<char> m_loaded_font;
  85. status m_status;
  86. bool m_big_endian;
  87. bool m_flip;
  88. int8u* m_indices;
  89. int8* m_glyphs;
  90. int8* m_bglyph;
  91. int8* m_eglyph;
  92. double m_w;
  93. double m_h;
  94. };
  95. //--------------------------------------------------------gsv_text_outline
  96. template<class Transformer = trans_affine> class gsv_text_outline
  97. {
  98. public:
  99. gsv_text_outline(gsv_text& text, Transformer& trans) :
  100. m_polyline(text),
  101. m_trans(m_polyline, trans)
  102. {
  103. }
  104. void width(double w)
  105. {
  106. m_polyline.width(w);
  107. }
  108. void transformer(const Transformer* trans)
  109. {
  110. m_trans->transformer(trans);
  111. }
  112. void rewind(unsigned path_id)
  113. {
  114. m_trans.rewind(path_id);
  115. m_polyline.line_join(round_join);
  116. m_polyline.line_cap(round_cap);
  117. }
  118. unsigned vertex(double* x, double* y)
  119. {
  120. return m_trans.vertex(x, y);
  121. }
  122. private:
  123. conv_stroke<gsv_text> m_polyline;
  124. conv_transform<conv_stroke<gsv_text>, Transformer> m_trans;
  125. };
  126. }
  127. #endif