Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
8.3 KiB

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