gdiplusstringformat.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * gdiplusstringformat.h
  3. *
  4. * GDI+ StringFormat class
  5. *
  6. * This file is part of the w32api package.
  7. *
  8. * Contributors:
  9. * Created by Markus Koenig <markus@stber-koenig.de>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. */
  22. #ifndef __GDIPLUS_STRINGFORMAT_H
  23. #define __GDIPLUS_STRINGFORMAT_H
  24. #if __GNUC__ >=3
  25. #pragma GCC system_header
  26. #endif
  27. #ifndef __cplusplus
  28. #error "A C++ compiler is required to include gdiplusstringformat.h."
  29. #endif
  30. class StringFormat: public GdiplusBase
  31. {
  32. friend class Graphics;
  33. friend class GraphicsPath;
  34. public:
  35. static const StringFormat* GenericDefault();
  36. static const StringFormat* GenericTypographic();
  37. StringFormat(INT formatFlags = 0, LANGID language = LANG_NEUTRAL):
  38. nativeStringFormat(NULL), lastStatus(Ok)
  39. {
  40. lastStatus = DllExports::GdipCreateStringFormat(
  41. formatFlags, language, &nativeStringFormat);
  42. }
  43. StringFormat(const StringFormat *format):
  44. nativeStringFormat(NULL), lastStatus(Ok)
  45. {
  46. lastStatus = DllExports::GdipCloneStringFormat(
  47. format ? format->nativeStringFormat : NULL,
  48. &nativeStringFormat);
  49. }
  50. ~StringFormat()
  51. {
  52. DllExports::GdipDeleteStringFormat(nativeStringFormat);
  53. }
  54. StringFormat* Clone() const
  55. {
  56. GpStringFormat *cloneStringFormat = NULL;
  57. Status status = updateStatus(DllExports::GdipCloneStringFormat(
  58. nativeStringFormat, &cloneStringFormat));
  59. if (status == Ok) {
  60. StringFormat *result = new StringFormat(
  61. cloneStringFormat, lastStatus);
  62. if (!result) {
  63. DllExports::GdipDeleteStringFormat(cloneStringFormat);
  64. lastStatus = OutOfMemory;
  65. }
  66. return result;
  67. } else {
  68. return NULL;
  69. }
  70. }
  71. StringAlignment GetAlignment() const
  72. {
  73. StringAlignment result = StringAlignmentNear;
  74. updateStatus(DllExports::GdipGetStringFormatAlign(
  75. nativeStringFormat, &result));
  76. return result;
  77. }
  78. LANGID GetDigitSubstitutionLanguage() const
  79. {
  80. LANGID result = 0;
  81. StringDigitSubstitute method;
  82. updateStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  83. nativeStringFormat, &result, &method));
  84. return result;
  85. }
  86. StringDigitSubstitute GetDigitSubstitutionMethod() const
  87. {
  88. LANGID language;
  89. StringDigitSubstitute result = StringDigitSubstituteUser;
  90. updateStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  91. nativeStringFormat, &language, &result));
  92. return result;
  93. }
  94. INT GetFormatFlags() const
  95. {
  96. INT result = 0;
  97. updateStatus(DllExports::GdipGetStringFormatFlags(
  98. nativeStringFormat, &result));
  99. return result;
  100. }
  101. HotkeyPrefix GetHotkeyPrefix() const
  102. {
  103. HotkeyPrefix result = HotkeyPrefixNone;
  104. updateStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
  105. nativeStringFormat, (INT*) &result));
  106. return result;
  107. }
  108. Status GetLastStatus() const
  109. {
  110. Status result = lastStatus;
  111. lastStatus = Ok;
  112. return result;
  113. }
  114. StringAlignment GetLineAlignment() const
  115. {
  116. StringAlignment result = StringAlignmentNear;
  117. updateStatus(DllExports::GdipGetStringFormatLineAlign(
  118. nativeStringFormat, &result));
  119. return result;
  120. }
  121. INT GetMeasurableCharacterRangeCount() const
  122. {
  123. INT result = 0;
  124. updateStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
  125. nativeStringFormat, &result));
  126. return result;
  127. }
  128. INT GetTabStopCount() const
  129. {
  130. INT result = 0;
  131. updateStatus(DllExports::GdipGetStringFormatTabStopCount(
  132. nativeStringFormat, &result));
  133. return result;
  134. }
  135. Status GetTabStops(INT count, REAL *firstTabOffset, REAL *tabStops)
  136. {
  137. return updateStatus(DllExports::GdipGetStringFormatTabStops(
  138. nativeStringFormat, count,
  139. firstTabOffset, tabStops));
  140. }
  141. StringTrimming GetTrimming() const
  142. {
  143. StringTrimming result = StringTrimmingNone;
  144. updateStatus(DllExports::GdipGetStringFormatTrimming(
  145. nativeStringFormat, &result));
  146. return result;
  147. }
  148. Status SetAlignment(StringAlignment align)
  149. {
  150. return updateStatus(DllExports::GdipSetStringFormatAlign(
  151. nativeStringFormat, align));
  152. }
  153. Status SetDigitSubstitution(LANGID language,
  154. StringDigitSubstitute substitute)
  155. {
  156. return updateStatus(DllExports::GdipSetStringFormatDigitSubstitution(
  157. nativeStringFormat, language, substitute));
  158. }
  159. Status SetFormatFlags(INT flags)
  160. {
  161. return updateStatus(DllExports::GdipSetStringFormatFlags(
  162. nativeStringFormat, flags));
  163. }
  164. Status SetHotkeyPrefix(HotkeyPrefix hotkeyPrefix)
  165. {
  166. return updateStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
  167. nativeStringFormat, (INT) hotkeyPrefix));
  168. }
  169. Status SetLineAlignment(StringAlignment align)
  170. {
  171. return updateStatus(DllExports::GdipSetStringFormatLineAlign(
  172. nativeStringFormat, align));
  173. }
  174. Status SetMeasurableCharacterRanges(INT rangeCount,
  175. const CharacterRange *ranges)
  176. {
  177. return updateStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
  178. nativeStringFormat, rangeCount, ranges));
  179. }
  180. Status SetTabStops(REAL firstTabOffset, INT count, const REAL *tabStops)
  181. {
  182. return updateStatus(DllExports::GdipSetStringFormatTabStops(
  183. nativeStringFormat, firstTabOffset,
  184. count, tabStops));
  185. }
  186. Status SetTrimming(StringTrimming trimming)
  187. {
  188. return updateStatus(DllExports::GdipSetStringFormatTrimming(
  189. nativeStringFormat, trimming));
  190. }
  191. private:
  192. StringFormat(GpStringFormat *stringFormat, Status status):
  193. nativeStringFormat(stringFormat), lastStatus(status) {}
  194. StringFormat(const StringFormat&);
  195. StringFormat& operator=(const StringFormat&);
  196. Status updateStatus(Status newStatus) const
  197. {
  198. if (newStatus != Ok) lastStatus = newStatus;
  199. return newStatus;
  200. }
  201. GpStringFormat *nativeStringFormat;
  202. mutable Status lastStatus;
  203. };
  204. // FIXME: do StringFormat::GenericDefault() et al. need to be thread safe?
  205. // FIXME: maybe put this in gdiplus.c?
  206. extern "C" void *_GdipStringFormatCachedGenericDefault;
  207. extern "C" void *_GdipStringFormatCachedGenericTypographic;
  208. __inline__ const StringFormat* StringFormat::GenericDefault()
  209. {
  210. if (!_GdipStringFormatCachedGenericDefault) {
  211. GpStringFormat *nativeStringFormat = 0;
  212. Status status = DllExports::GdipStringFormatGetGenericDefault(
  213. &nativeStringFormat);
  214. if (status == Ok && nativeStringFormat) {
  215. _GdipStringFormatCachedGenericDefault = (void*)
  216. new StringFormat(nativeStringFormat, Ok);
  217. }
  218. }
  219. return (StringFormat*) _GdipStringFormatCachedGenericDefault;
  220. }
  221. __inline__ const StringFormat* StringFormat::GenericTypographic()
  222. {
  223. if (!_GdipStringFormatCachedGenericTypographic) {
  224. GpStringFormat *nativeStringFormat = 0;
  225. Status status = DllExports::GdipStringFormatGetGenericTypographic(
  226. &nativeStringFormat);
  227. if (status == Ok && nativeStringFormat) {
  228. _GdipStringFormatCachedGenericTypographic = (void*)
  229. new StringFormat(nativeStringFormat, Ok);
  230. }
  231. }
  232. return (StringFormat*) _GdipStringFormatCachedGenericTypographic;
  233. }
  234. #endif /* __GDIPLUS_STRINGFORMAT_H */