Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

382 rader
9.1 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusStringFormat.h
  8. *
  9. * Abstract:
  10. *
  11. * String format specification for DrawString and text APIs
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSSTRINGFORMAT_H
  15. #define _GDIPLUSSTRINGFORMAT_H
  16. class StringFormat : public GdiplusBase
  17. {
  18. public:
  19. friend class Graphics;
  20. friend class GraphicsPath;
  21. StringFormat(
  22. IN INT formatFlags = 0,
  23. IN LANGID language = LANG_NEUTRAL
  24. )
  25. {
  26. nativeFormat = NULL;
  27. lastError = DllExports::GdipCreateStringFormat(
  28. formatFlags,
  29. language,
  30. &nativeFormat
  31. );
  32. }
  33. static const StringFormat *GenericDefault();
  34. static const StringFormat *GenericTypographic();
  35. // Constructor based on existing string format
  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. #ifndef DCR_USE_NEW_152154
  76. Status SetLineSpacing(
  77. IN REAL amount = 1.0f,
  78. IN LineSpacing method = LineSpacingRecommended
  79. )
  80. {
  81. return SetStatus(DllExports::GdipSetStringFormatLineSpacing(
  82. nativeFormat,
  83. amount,
  84. method
  85. ));
  86. }
  87. #endif
  88. Status SetAlignment(IN StringAlignment align)
  89. {
  90. return SetStatus(DllExports::GdipSetStringFormatAlign(
  91. nativeFormat,
  92. align
  93. ));
  94. }
  95. StringAlignment GetAlignment() const
  96. {
  97. StringAlignment alignment;
  98. SetStatus(DllExports::GdipGetStringFormatAlign(
  99. nativeFormat,
  100. &alignment
  101. ));
  102. return alignment;
  103. }
  104. Status SetLineAlignment(IN StringAlignment align)
  105. {
  106. return SetStatus(DllExports::GdipSetStringFormatLineAlign(
  107. nativeFormat,
  108. align
  109. ));
  110. }
  111. StringAlignment GetLineAlignment() const
  112. {
  113. StringAlignment alignment;
  114. SetStatus(DllExports::GdipGetStringFormatLineAlign(
  115. nativeFormat,
  116. &alignment
  117. ));
  118. return alignment;
  119. }
  120. Status SetHotkeyPrefix(IN HotkeyPrefix hotkeyPrefix)
  121. {
  122. return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
  123. nativeFormat,
  124. (INT)hotkeyPrefix
  125. ));
  126. }
  127. HotkeyPrefix GetHotkeyPrefix() const
  128. {
  129. HotkeyPrefix hotkeyPrefix;
  130. SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
  131. nativeFormat,
  132. (INT*)&hotkeyPrefix
  133. ));
  134. return hotkeyPrefix;
  135. }
  136. Status SetTabStops(
  137. IN REAL firstTabOffset,
  138. IN INT count,
  139. IN const REAL *tabStops
  140. )
  141. {
  142. return SetStatus(DllExports::GdipSetStringFormatTabStops(
  143. nativeFormat,
  144. firstTabOffset,
  145. count,
  146. tabStops
  147. ));
  148. }
  149. INT GetTabStopCount() const
  150. {
  151. INT count;
  152. SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
  153. return count;
  154. }
  155. Status GetTabStops(
  156. IN INT count,
  157. OUT REAL *firstTabOffset,
  158. OUT REAL *tabStops
  159. ) const
  160. {
  161. return SetStatus(DllExports::GdipGetStringFormatTabStops(
  162. nativeFormat,
  163. count,
  164. firstTabOffset,
  165. tabStops
  166. ));
  167. }
  168. #ifdef DCR_USE_NEW_146933
  169. Status SetDigitSubstitution(
  170. IN LANGID language,
  171. IN StringDigitSubstitute substitute
  172. )
  173. {
  174. return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(
  175. nativeFormat,
  176. language,
  177. substitute
  178. ));
  179. }
  180. LANGID GetDigitSubstitutionLanguage(
  181. ) const
  182. {
  183. LANGID language;
  184. SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  185. nativeFormat,
  186. &language,
  187. NULL
  188. ));
  189. return language;
  190. }
  191. StringDigitSubstitute GetDigitSubstitutionMethod(
  192. ) const
  193. {
  194. StringDigitSubstitute substitute;
  195. SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  196. nativeFormat,
  197. NULL,
  198. &substitute
  199. ));
  200. return substitute;
  201. }
  202. #endif // DCR_USE_NEW_146933
  203. // String trimming. How to handle more text than can be displayed
  204. // in the limits available.
  205. Status SetTrimming(IN StringTrimming trimming)
  206. {
  207. return SetStatus(DllExports::GdipSetStringFormatTrimming(
  208. nativeFormat,
  209. trimming
  210. ));
  211. }
  212. StringTrimming GetTrimming() const
  213. {
  214. StringTrimming trimming;
  215. SetStatus(DllExports::GdipGetStringFormatTrimming(
  216. nativeFormat,
  217. &trimming
  218. ));
  219. return trimming;
  220. }
  221. #ifdef DCR_USE_NEW_174340
  222. Status SetMeasurableCharacterRanges(
  223. IN INT rangeCount,
  224. IN const CharacterRange *ranges
  225. )
  226. {
  227. return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
  228. nativeFormat,
  229. rangeCount,
  230. ranges
  231. ));
  232. }
  233. INT GetMeasurableCharacterRangeCount()
  234. {
  235. INT count;
  236. SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
  237. nativeFormat,
  238. &count
  239. ));
  240. return count;
  241. }
  242. #endif
  243. // GetLastStatus - return last error code and clear error code
  244. Status GetLastStatus() const
  245. {
  246. Status lastStatus = lastError;
  247. lastError = Ok;
  248. return lastStatus;
  249. }
  250. protected:
  251. Status SetStatus(GpStatus newStatus) const
  252. {
  253. if (newStatus == Ok)
  254. {
  255. return Ok;
  256. }
  257. else
  258. {
  259. return lastError = newStatus;
  260. }
  261. }
  262. // Not allowed and move to private
  263. StringFormat(const StringFormat &source)
  264. {
  265. nativeFormat = NULL;
  266. lastError = DllExports::GdipCloneStringFormat(
  267. source.nativeFormat,
  268. &nativeFormat
  269. );
  270. }
  271. StringFormat& operator=(const StringFormat &source)
  272. {
  273. DllExports::GdipDeleteStringFormat(nativeFormat);
  274. lastError = DllExports::GdipCloneStringFormat(
  275. source.nativeFormat,
  276. &nativeFormat
  277. );
  278. return *this;
  279. }
  280. // private constructor for copy
  281. StringFormat(GpStringFormat * clonedStringFormat, Status status)
  282. {
  283. lastError = status;
  284. nativeFormat = clonedStringFormat;
  285. }
  286. GpStringFormat *nativeFormat;
  287. mutable Status lastError;
  288. };
  289. // Generic constant string formats.
  290. static BYTE GenericTypographicStringFormatBuffer[sizeof(StringFormat)] = {0};
  291. static BYTE GenericDefaultStringFormatBuffer[sizeof(StringFormat)] = {0};
  292. static StringFormat *GenericTypographicStringFormat = NULL;
  293. static StringFormat *GenericDefaultStringFormat = NULL;
  294. // Define the generic string formats
  295. inline const StringFormat *StringFormat::GenericDefault()
  296. {
  297. if (GenericDefaultStringFormat != NULL)
  298. {
  299. return GenericDefaultStringFormat;
  300. }
  301. GenericDefaultStringFormat =
  302. (StringFormat*)GenericDefaultStringFormatBuffer;
  303. GenericDefaultStringFormat->lastError =
  304. DllExports::GdipStringFormatGetGenericDefault(
  305. &(GenericDefaultStringFormat->nativeFormat)
  306. );
  307. return GenericDefaultStringFormat;
  308. }
  309. inline const StringFormat *StringFormat::GenericTypographic()
  310. {
  311. if (GenericTypographicStringFormat != NULL)
  312. {
  313. return GenericTypographicStringFormat;
  314. }
  315. GenericTypographicStringFormat =
  316. (StringFormat*)GenericTypographicStringFormatBuffer;
  317. GenericTypographicStringFormat->lastError =
  318. DllExports::GdipStringFormatGetGenericTypographic(
  319. &GenericTypographicStringFormat->nativeFormat
  320. );
  321. return GenericTypographicStringFormat;
  322. }
  323. #endif // !_GDIPLUSSTRINGFORMAT_H