GdiPlusStringFormat.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //Download by http://www.NewXing.com
  2. /**************************************************************************\
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  5. *
  6. * Module Name:
  7. *
  8. * GdiplusStringFormat.h
  9. *
  10. * Abstract:
  11. *
  12. * GDI+ StringFormat class
  13. *
  14. \**************************************************************************/
  15. #ifndef _GDIPLUSSTRINGFORMAT_H
  16. #define _GDIPLUSSTRINGFORMAT_H
  17. class StringFormat : public GdiplusBase
  18. {
  19. public:
  20. friend class Graphics;
  21. friend class GraphicsPath;
  22. StringFormat(
  23. IN INT formatFlags = 0,
  24. IN LANGID language = LANG_NEUTRAL
  25. )
  26. {
  27. nativeFormat = NULL;
  28. lastError = DllExports::GdipCreateStringFormat(
  29. formatFlags,
  30. language,
  31. &nativeFormat
  32. );
  33. }
  34. static const StringFormat *GenericDefault();
  35. static const StringFormat *GenericTypographic();
  36. StringFormat(
  37. IN const StringFormat *format
  38. )
  39. {
  40. nativeFormat = NULL;
  41. lastError = DllExports::GdipCloneStringFormat(
  42. format ? format->nativeFormat : NULL,
  43. &nativeFormat
  44. );
  45. }
  46. StringFormat *Clone() const
  47. {
  48. GpStringFormat *clonedStringFormat = NULL;
  49. lastError = DllExports::GdipCloneStringFormat(
  50. nativeFormat,
  51. &clonedStringFormat
  52. );
  53. if (lastError == Ok)
  54. return new StringFormat(clonedStringFormat, lastError);
  55. else
  56. return NULL;
  57. }
  58. ~StringFormat()
  59. {
  60. DllExports::GdipDeleteStringFormat(nativeFormat);
  61. }
  62. Status SetFormatFlags(IN INT flags)
  63. {
  64. return SetStatus(DllExports::GdipSetStringFormatFlags(
  65. nativeFormat,
  66. flags
  67. ));
  68. }
  69. INT GetFormatFlags() const
  70. {
  71. INT flags;
  72. SetStatus(DllExports::GdipGetStringFormatFlags(nativeFormat, &flags));
  73. return flags;
  74. }
  75. Status SetAlignment(IN StringAlignment align)
  76. {
  77. return SetStatus(DllExports::GdipSetStringFormatAlign(
  78. nativeFormat,
  79. align
  80. ));
  81. }
  82. StringAlignment GetAlignment() const
  83. {
  84. StringAlignment alignment;
  85. SetStatus(DllExports::GdipGetStringFormatAlign(
  86. nativeFormat,
  87. &alignment
  88. ));
  89. return alignment;
  90. }
  91. Status SetLineAlignment(IN StringAlignment align)
  92. {
  93. return SetStatus(DllExports::GdipSetStringFormatLineAlign(
  94. nativeFormat,
  95. align
  96. ));
  97. }
  98. StringAlignment GetLineAlignment() const
  99. {
  100. StringAlignment alignment;
  101. SetStatus(DllExports::GdipGetStringFormatLineAlign(
  102. nativeFormat,
  103. &alignment
  104. ));
  105. return alignment;
  106. }
  107. Status SetHotkeyPrefix(IN HotkeyPrefix hotkeyPrefix)
  108. {
  109. return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
  110. nativeFormat,
  111. (INT)hotkeyPrefix
  112. ));
  113. }
  114. HotkeyPrefix GetHotkeyPrefix() const
  115. {
  116. HotkeyPrefix hotkeyPrefix;
  117. SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
  118. nativeFormat,
  119. (INT*)&hotkeyPrefix
  120. ));
  121. return hotkeyPrefix;
  122. }
  123. Status SetTabStops(
  124. IN REAL firstTabOffset,
  125. IN INT count,
  126. IN const REAL *tabStops
  127. )
  128. {
  129. return SetStatus(DllExports::GdipSetStringFormatTabStops(
  130. nativeFormat,
  131. firstTabOffset,
  132. count,
  133. tabStops
  134. ));
  135. }
  136. INT GetTabStopCount() const
  137. {
  138. INT count;
  139. SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
  140. return count;
  141. }
  142. Status GetTabStops(
  143. IN INT count,
  144. OUT REAL *firstTabOffset,
  145. OUT REAL *tabStops
  146. ) const
  147. {
  148. return SetStatus(DllExports::GdipGetStringFormatTabStops(
  149. nativeFormat,
  150. count,
  151. firstTabOffset,
  152. tabStops
  153. ));
  154. }
  155. Status SetDigitSubstitution(
  156. IN LANGID language,
  157. IN StringDigitSubstitute substitute
  158. )
  159. {
  160. return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(
  161. nativeFormat,
  162. language,
  163. substitute
  164. ));
  165. }
  166. LANGID GetDigitSubstitutionLanguage(
  167. ) const
  168. {
  169. LANGID language;
  170. SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  171. nativeFormat,
  172. &language,
  173. NULL
  174. ));
  175. return language;
  176. }
  177. StringDigitSubstitute GetDigitSubstitutionMethod(
  178. ) const
  179. {
  180. StringDigitSubstitute substitute;
  181. SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  182. nativeFormat,
  183. NULL,
  184. &substitute
  185. ));
  186. return substitute;
  187. }
  188. Status SetTrimming(IN StringTrimming trimming)
  189. {
  190. return SetStatus(DllExports::GdipSetStringFormatTrimming(
  191. nativeFormat,
  192. trimming
  193. ));
  194. }
  195. StringTrimming StringFormat::GetTrimming() const
  196. {
  197. StringTrimming trimming;
  198. SetStatus(DllExports::GdipGetStringFormatTrimming(
  199. nativeFormat,
  200. &trimming
  201. ));
  202. return trimming;
  203. }
  204. Status SetMeasurableCharacterRanges(
  205. IN INT rangeCount,
  206. IN const CharacterRange *ranges
  207. )
  208. {
  209. return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
  210. nativeFormat,
  211. rangeCount,
  212. ranges
  213. ));
  214. }
  215. INT GetMeasurableCharacterRangeCount()
  216. {
  217. INT count;
  218. SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
  219. nativeFormat,
  220. &count
  221. ));
  222. return count;
  223. }
  224. Status GetLastStatus() const
  225. {
  226. Status lastStatus = lastError;
  227. lastError = Ok;
  228. return lastStatus;
  229. }
  230. protected:
  231. Status SetStatus(GpStatus newStatus) const
  232. {
  233. if (newStatus == Ok)
  234. {
  235. return Ok;
  236. }
  237. else
  238. {
  239. return lastError = newStatus;
  240. }
  241. }
  242. StringFormat(const StringFormat &source)
  243. {
  244. nativeFormat = NULL;
  245. lastError = DllExports::GdipCloneStringFormat(
  246. source.nativeFormat,
  247. &nativeFormat
  248. );
  249. }
  250. StringFormat& operator=(const StringFormat &source)
  251. {
  252. DllExports::GdipDeleteStringFormat(nativeFormat);
  253. lastError = DllExports::GdipCloneStringFormat(
  254. source.nativeFormat,
  255. &nativeFormat
  256. );
  257. return *this;
  258. }
  259. StringFormat(GpStringFormat * clonedStringFormat, Status status)
  260. {
  261. lastError = status;
  262. nativeFormat = clonedStringFormat;
  263. }
  264. GpStringFormat *nativeFormat;
  265. mutable Status lastError;
  266. };
  267. static BYTE GenericTypographicStringFormatBuffer[sizeof(StringFormat)] = {0};
  268. static BYTE GenericDefaultStringFormatBuffer[sizeof(StringFormat)] = {0};
  269. inline const StringFormat *StringFormat::GenericDefault()
  270. {
  271. StringFormat * genericDefaultStringFormat =
  272. (StringFormat*)GenericDefaultStringFormatBuffer;
  273. genericDefaultStringFormat->lastError =
  274. DllExports::GdipStringFormatGetGenericDefault(
  275. &(genericDefaultStringFormat->nativeFormat)
  276. );
  277. return genericDefaultStringFormat;
  278. }
  279. inline const StringFormat *StringFormat::GenericTypographic()
  280. {
  281. StringFormat * genericTypographicStringFormat =
  282. (StringFormat*)GenericTypographicStringFormatBuffer;
  283. genericTypographicStringFormat->lastError =
  284. DllExports::GdipStringFormatGetGenericTypographic(
  285. &genericTypographicStringFormat->nativeFormat
  286. );
  287. return genericTypographicStringFormat;
  288. }
  289. #endif // !_GDIPLUSSTRINGFORMAT_H