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.

628 lines
27 KiB

  1. // Dict.cpp : Implementation of CDict
  2. #include "stdafx.h"
  3. #include "MSAAText.h"
  4. #include "MSAAAdapter.h"
  5. #include "Dict.h"
  6. #include <initguid.h>
  7. #include <tsattrs.h>
  8. #include <math.h>
  9. const int STR_RESOURCE_OFFSET = 4000;
  10. const int STR_WEIGHT_RESOURCE_OFFSET = 4400;
  11. const int STR_COLOR_RESOURCE_OFFSET = 4500;
  12. const int STR_BOOL_TRUE = 4421;
  13. const int STR_BOOL_FALSE = 4422;
  14. #define ARRAYSIZE( a ) (sizeof(a)/sizeof(a[0]))
  15. DEFINE_GUID(GUID_NULL, 0x00000000,0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
  16. TermInfo g_Terms [ ] =
  17. {
  18. {&TSATTRID_Font, NULL, L"font", 0, CDict::ConvertBoolToString },
  19. {&TSATTRID_Font_FaceName, &TSATTRID_Font, L"facename", 1, CDict::ConvertBSTRToString },
  20. {&TSATTRID_Font_SizePts, &TSATTRID_Font, L"sizePts", 2, CDict::ConvertPtsToString },
  21. {&TSATTRID_Font_Style, &TSATTRID_Font, L"style", 3, CDict::ConvertBoolToString },
  22. {&TSATTRID_Font_Style_Bold, &TSATTRID_Font_Style, L"bold", 4, CDict::ConvertBoolToString },
  23. {&TSATTRID_Font_Style_Italic, &TSATTRID_Font_Style, L"italic", 5, CDict::ConvertBoolToString },
  24. {&TSATTRID_Font_Style_SmallCaps, &TSATTRID_Font_Style, L"smallcaps", 6, CDict::ConvertBoolToString },
  25. {&TSATTRID_Font_Style_Capitalize, &TSATTRID_Font_Style, L"capitalize", 7, CDict::ConvertBoolToString },
  26. {&TSATTRID_Font_Style_Uppercase, &TSATTRID_Font_Style, L"uppercase", 8, CDict::ConvertBoolToString },
  27. {&TSATTRID_Font_Style_Lowercase, &TSATTRID_Font_Style, L"lowercase", 9, CDict::ConvertBoolToString },
  28. {&TSATTRID_Font_Style_Animation, NULL, L"animation", 10, CDict::ConvertBoolToString },
  29. {&TSATTRID_Font_Style_Animation_LasVegasLights, &TSATTRID_Font_Style_Animation, L"LasVegas_lights", 11, CDict::ConvertBoolToString },
  30. {&TSATTRID_Font_Style_Animation_BlinkingBackground, &TSATTRID_Font_Style_Animation, L"blinking_background",12,CDict::ConvertBoolToString },
  31. {&TSATTRID_Font_Style_Animation_SparkleText, &TSATTRID_Font_Style_Animation, L"sparkle_text", 13, CDict::ConvertBoolToString },
  32. {&TSATTRID_Font_Style_Animation_MarchingBlackAnts, &TSATTRID_Font_Style_Animation, L"marching_black_ants",14,CDict::ConvertBoolToString },
  33. {&TSATTRID_Font_Style_Animation_MarchingRedAnts, &TSATTRID_Font_Style_Animation, L"marching_red_ants",15,CDict::ConvertBoolToString },
  34. {&TSATTRID_Font_Style_Animation_Shimmer, &TSATTRID_Font_Style_Animation, L"shimmer", 16, CDict::ConvertBoolToString },
  35. {&TSATTRID_Font_Style_Animation_WipeDown, &TSATTRID_Font_Style_Animation, L"wipeDown", 17, CDict::ConvertBoolToString },
  36. {&TSATTRID_Font_Style_Animation_WipeRight, &TSATTRID_Font_Style_Animation, L"wipeRight", 18, CDict::ConvertBoolToString },
  37. {&TSATTRID_Font_Style_Emboss, &TSATTRID_Font_Style, L"emboss", 19, CDict::ConvertBoolToString },
  38. {&TSATTRID_Font_Style_Engrave, &TSATTRID_Font_Style, L"engrave", 20, CDict::ConvertBoolToString },
  39. {&TSATTRID_Font_Style_Kerning, &TSATTRID_Font_Style, L"kerning", 21, CDict::ConvertBoolToString },
  40. {&TSATTRID_Font_Style_Outlined, &TSATTRID_Font_Style, L"outlined", 22, CDict::ConvertBoolToString },
  41. {&TSATTRID_Font_Style_Position, &TSATTRID_Font_Style, L"position", 23, CDict::ConvertBoolToString },
  42. {&TSATTRID_Font_Style_Protected, &TSATTRID_Font_Style, L"potected", 24, CDict::ConvertBoolToString },
  43. {&TSATTRID_Font_Style_Shadow, &TSATTRID_Font_Style, L"shadow", 25, CDict::ConvertBoolToString },
  44. {&TSATTRID_Font_Style_Spacing, &TSATTRID_Font_Style, L"spacing", 26, CDict::ConvertPtsToString },
  45. {&TSATTRID_Font_Style_Weight, &TSATTRID_Font_Style, L"weight", 27, CDict::ConvertBoolToString },
  46. {&TSATTRID_Font_Style_Height, &TSATTRID_Font_Style, L"height", 28, CDict::ConvertPtsToString },
  47. {&TSATTRID_Font_Style_Underline, &TSATTRID_Font_Style, L"underline", 29, CDict::ConvertBoolToString },
  48. {&TSATTRID_Font_Style_Underline_Single, &TSATTRID_Font_Style_Underline, L"single", 30, CDict::ConvertBoolToString },
  49. {&TSATTRID_Font_Style_Underline_Double, &TSATTRID_Font_Style_Underline, L"double", 31, CDict::ConvertBoolToString },
  50. {&TSATTRID_Font_Style_Strikethrough, &TSATTRID_Font_Style, L"strike_through", 32, CDict::ConvertBoolToString },
  51. {&TSATTRID_Font_Style_Strikethrough_Single, &TSATTRID_Font_Style_Strikethrough, L"strike_through_single",33,CDict::ConvertBoolToString },
  52. {&TSATTRID_Font_Style_Strikethrough_Double, &TSATTRID_Font_Style_Strikethrough, L"strike_through_double",34,CDict::ConvertBoolToString },
  53. {&TSATTRID_Font_Style_Overline, &TSATTRID_Font_Style, L"overline", 35, CDict::ConvertBoolToString },
  54. {&TSATTRID_Font_Style_Overline_Single, &TSATTRID_Font_Style, L"overline_single", 36, CDict::ConvertBoolToString },
  55. {&TSATTRID_Font_Style_Overline_Double, &TSATTRID_Font_Style, L"overline_double", 37, CDict::ConvertBoolToString },
  56. {&TSATTRID_Font_Style_Blink, &TSATTRID_Font_Style, L"blink", 38, CDict::ConvertBoolToString },
  57. {&TSATTRID_Font_Style_Subscript, &TSATTRID_Font_Style, L"subscript", 39, CDict::ConvertBoolToString },
  58. {&TSATTRID_Font_Style_Superscript, &TSATTRID_Font_Style, L"superscript", 40, CDict::ConvertBoolToString },
  59. {&TSATTRID_Font_Style_Color, &TSATTRID_Font_Style, L"color", 41, CDict::ConvertColorToString },
  60. {&TSATTRID_Font_Style_BackgroundColor, &TSATTRID_Font_Style, L"background_color", 42, CDict::ConvertColorToString },
  61. {&TSATTRID_Text, NULL, L"text", 43, CDict::ConvertBoolToString },
  62. {&TSATTRID_Text_VerticalWriting, &TSATTRID_Text, L"vertical writing", 44, CDict::ConvertBoolToString },
  63. {&TSATTRID_Text_RightToLeft, &TSATTRID_Text, L"righttoleft", 45, CDict::ConvertBoolToString },
  64. {&TSATTRID_Text_Orientation, &TSATTRID_Text, L"orientation", 46, CDict::ConvertBoolToString },
  65. {&TSATTRID_Text_Language, &TSATTRID_Text, L"language", 47, CDict::ConvertLangIDToString },
  66. {&TSATTRID_Text_ReadOnly, &TSATTRID_Text, L"read only", 48, CDict::ConvertBoolToString },
  67. {&TSATTRID_Text_EmbeddedObject, &TSATTRID_Text, L"embedded_object", 49, CDict::ConvertBoolToString },
  68. {&TSATTRID_Text_Link, &TSATTRID_Text, L"link", 50, CDict::ConvertBoolToString },
  69. {&TSATTRID_Text_Alignment, NULL, L"alignment", 51, CDict::ConvertBoolToString },
  70. {&TSATTRID_Text_Alignment_Left, &TSATTRID_Text, L"left", 52, CDict::ConvertBoolToString },
  71. {&TSATTRID_Text_Alignment_Right, &TSATTRID_Text, L"right", 53, CDict::ConvertBoolToString },
  72. {&TSATTRID_Text_Alignment_Center, &TSATTRID_Text, L"center", 54, CDict::ConvertBoolToString },
  73. {&TSATTRID_Text_Alignment_Justify, &TSATTRID_Text, L"justify", 55, CDict::ConvertBoolToString },
  74. {&TSATTRID_Text_Hyphenation, &TSATTRID_Text, L"hyphenation", 56, CDict::ConvertBoolToString },
  75. {&TSATTRID_Text_Para, &TSATTRID_Text, L"paragraph", 57, CDict::ConvertBoolToString },
  76. {&TSATTRID_Text_Para_FirstLineIndent, &TSATTRID_Text_Para, L"first_line_indent", 58, CDict::ConvertPtsToString },
  77. {&TSATTRID_Text_Para_LeftIndent, &TSATTRID_Text_Para, L"left-indent", 59, CDict::ConvertPtsToString },
  78. {&TSATTRID_Text_Para_RightIndent, &TSATTRID_Text_Para, L"right_indent", 60, CDict::ConvertPtsToString },
  79. {&TSATTRID_Text_Para_SpaceAfter, &TSATTRID_Text_Para, L"space_after", 61, CDict::ConvertPtsToString },
  80. {&TSATTRID_Text_Para_SpaceBefore, &TSATTRID_Text_Para, L"space_before", 62, CDict::ConvertPtsToString },
  81. {&TSATTRID_Text_Para_LineSpacing, NULL, L"line_spacing", 63, CDict::ConvertBoolToString },
  82. {&TSATTRID_Text_Para_LineSpacing_Single, &TSATTRID_Text_Para, L"single", 64, CDict::ConvertBoolToString },
  83. {&TSATTRID_Text_Para_LineSpacing_OnePtFive, &TSATTRID_Text_Para, L"one_pt_five", 65, CDict::ConvertBoolToString },
  84. {&TSATTRID_Text_Para_LineSpacing_Double, &TSATTRID_Text_Para, L"double", 66, CDict::ConvertBoolToString },
  85. {&TSATTRID_Text_Para_LineSpacing_AtLeast, &TSATTRID_Text_Para, L"at_least", 67, CDict::ConvertBoolToString },
  86. {&TSATTRID_Text_Para_LineSpacing_Exactly, &TSATTRID_Text_Para, L"exactly", 68, CDict::ConvertBoolToString },
  87. {&TSATTRID_Text_Para_LineSpacing_Multiple, &TSATTRID_Text_Para, L"multiple", 69, CDict::ConvertBoolToString },
  88. {&TSATTRID_List, NULL, L"list", 70, CDict::ConvertBoolToString },
  89. {&TSATTRID_List_LevelIndel, &TSATTRID_List, L"indent level", 71, CDict::ConvertBoolToString },
  90. {&TSATTRID_List_Type, NULL, L"type", 72, CDict::ConvertBoolToString },
  91. {&TSATTRID_List_Type_Bullet, &TSATTRID_List, L"bullet", 73, CDict::ConvertBoolToString },
  92. {&TSATTRID_List_Type_Arabic, &TSATTRID_List, L"arabic", 74, CDict::ConvertBoolToString },
  93. {&TSATTRID_List_Type_LowerLetter, &TSATTRID_List, L"lower_letter", 75, CDict::ConvertBoolToString },
  94. {&TSATTRID_List_Type_UpperLetter, &TSATTRID_List, L"upper_letter", 76, CDict::ConvertBoolToString },
  95. {&TSATTRID_List_Type_LowerRoman, &TSATTRID_List, L"lower_roman", 77, CDict::ConvertBoolToString },
  96. {&TSATTRID_List_Type_UpperRoman, &TSATTRID_List, L"upper_roman", 78, CDict::ConvertBoolToString },
  97. {&TSATTRID_App, NULL, L"Application", 79, CDict::ConvertBoolToString },
  98. {&TSATTRID_App_IncorrectSpelling, &TSATTRID_App, L"incorrect spelling", 80, CDict::ConvertBoolToString },
  99. {&TSATTRID_App_IncorrectGrammar, &TSATTRID_App, L"incorrect grammar", 81, CDict::ConvertBoolToString },
  100. };
  101. COLORREF g_ColorArray [] =
  102. {
  103. RGB( 0xF0, 0xF8, 0xFF ), // rgb 240,248,255 AliceBlue
  104. RGB( 0xFA, 0xEB, 0xD7 ), // rgb 250,235,215 AntiqueWhite
  105. RGB( 0x00, 0xFF, 0xFF ), // rgb 0,255,255 Aqua
  106. RGB( 0x7F, 0xFF, 0xD4 ), // rgb 127,255,212 Aquamarine
  107. RGB( 0xF0, 0xFF, 0xFF ), // rgb 240,255,255 Azure
  108. RGB( 0xF5, 0xF5, 0xDC ), // rgb 245,245,220 Beige
  109. RGB( 0xFF, 0xE4, 0xC4 ), // rgb 255,228,196 Bisque
  110. RGB( 0x00, 0x00, 0x00 ), // rgb 0,0,0 Black
  111. RGB( 0xFF, 0xEB, 0xCD ), // rgb 255,235,205 BlanchedAlmond
  112. RGB( 0x00, 0x00, 0xFF ), // rgb 0,0,255 Blue
  113. RGB( 0x8A, 0x2B, 0xE2 ), // rgb 138,43,226 BlueViolet
  114. RGB( 0xA5, 0x2A, 0x2A ), // rgb 165,42,42 Brown
  115. RGB( 0xDE, 0xB8, 0x87 ), // rgb 222,184,135 BurlyWood
  116. RGB( 0x5F, 0x9E, 0xA0 ), // rgb 95,158,160 CadetBlue
  117. RGB( 0x7F, 0xFF, 0x00 ), // rgb 127,255,0 Chartreuse
  118. RGB( 0xD2, 0x69, 0x1E ), // rgb 210,105,30 Chocolate
  119. RGB( 0xFF, 0x7F, 0x50 ), // rgb 255,127,80 Coral
  120. RGB( 0x64, 0x95, 0xED ), // rgb 100,149,237 CornflowerBlue
  121. RGB( 0xFF, 0xF8, 0xDC ), // rgb 255,248,220 Cornsilk
  122. RGB( 0xDC, 0x14, 0x3C ), // rgb 220,20,60 Crimson
  123. RGB( 0x00, 0xFF, 0xFF ), // rgb 0,255,255 Cyan
  124. RGB( 0x00, 0x00, 0x8B ), // rgb 0,0,139 DarkBlue
  125. RGB( 0x00, 0x8B, 0x8B ), // rgb 0,139,139 DarkCyan
  126. RGB( 0xB8, 0x86, 0x0B ), // rgb 184,134,11 DarkGoldenrod
  127. RGB( 0xA9, 0xA9, 0xA9 ), // rgb 169,169,169 DarkGray
  128. RGB( 0x00, 0x64, 0x00 ), // rgb 0,100,0 DarkGreen
  129. RGB( 0xBD, 0xB7, 0x6B ), // rgb 189,183,107 DarkKhaki
  130. RGB( 0x8B, 0x00, 0x8B ), // rgb 139,0,139 DarkMagenta
  131. RGB( 0x55, 0x6B, 0x2F ), // rgb 85,107,47 DarkOliveGreen
  132. RGB( 0xFF, 0x8C, 0x00 ), // rgb 255,140,0 DarkOrange
  133. RGB( 0x99, 0x32, 0xCC ), // rgb 153,50,204 DarkOrchid
  134. RGB( 0x8B, 0x00, 0x00 ), // rgb 139,0,0 DarkRed
  135. RGB( 0xE9, 0x96, 0x7A ), // rgb 233,150,122 DarkSalmon
  136. RGB( 0x8F, 0xBC, 0x8F ), // rgb 143,188,143 DarkSeaGreen
  137. RGB( 0x48, 0x3D, 0x8B ), // rgb 72,61,139 DarkSlateBlue
  138. RGB( 0x2F, 0x4F, 0x4F ), // rgb 47,79,79 DarkSlateGray
  139. RGB( 0x00, 0xCE, 0xD1 ), // rgb 0,206,209 DarkTurquoise
  140. RGB( 0x94, 0x00, 0xD3 ), // rgb 148,0,211 DarkViolet
  141. RGB( 0xFF, 0x14, 0x93 ), // rgb 255,20,147 DeepPink
  142. RGB( 0x00, 0xBF, 0xFF ), // rgb 0,191,255 DeepSkyBlue
  143. RGB( 0x69, 0x69, 0x69 ), // rgb 105,105,105 DimGray
  144. RGB( 0x1E, 0x90, 0xFF ), // rgb 30,144,255 DodgerBlue
  145. RGB( 0xB2, 0x22, 0x22 ), // rgb 178,34,34 FireBrick
  146. RGB( 0xFF, 0xFA, 0xF0 ), // rgb 255,250,240 FloralWhite
  147. RGB( 0x22, 0x8B, 0x22 ), // rgb 34,139,34 ForestGreen
  148. RGB( 0xFF, 0x00, 0xFF ), // rgb 255,0,255 Fuchsia
  149. RGB( 0xDC, 0xDC, 0xDC ), // rgb 220,220,220 Gainsboro
  150. RGB( 0xF8, 0xF8, 0xFF ), // rgb 248,248,255 GhostWhite
  151. RGB( 0xFF, 0xD7, 0x00 ), // rgb 255,215,0 Gold
  152. RGB( 0xDA, 0xA5, 0x20 ), // rgb 218,165,32 Goldenrod
  153. RGB( 0x80, 0x80, 0x80 ), // rgb 128,128,128 Gray
  154. RGB( 0x00, 0x80, 0x00 ), // rgb 0,128,0 Green
  155. RGB( 0xAD, 0xFF, 0x2F ), // rgb 173,255,47 GreenYellow
  156. RGB( 0xF0, 0xFF, 0xF0 ), // rgb 240,255,240 Honeydew
  157. RGB( 0xFF, 0x69, 0xB4 ), // rgb 255,105,180 HotPink
  158. RGB( 0xCD, 0x5C, 0x5C ), // rgb 205,92,92 IndianRed
  159. RGB( 0x4B, 0x00, 0x82 ), // rgb 75,0,130 Indigo
  160. RGB( 0xFF, 0xFF, 0xF0 ), // rgb 255,255,240 Ivory
  161. RGB( 0xF0, 0xE6, 0x8C ), // rgb 240,230,140 Khaki
  162. RGB( 0xE6, 0xE6, 0xFA ), // rgb 230,230,250 Lavender
  163. RGB( 0xFF, 0xF0, 0xF5 ), // rgb 255,240,245 LavenderBlush
  164. RGB( 0x7C, 0xFC, 0x00 ), // rgb 124,252,0 LawnGreen
  165. RGB( 0xFF, 0xFA, 0xCD ), // rgb 255,250,205 LemonChiffon
  166. RGB( 0xAD, 0xD8, 0xE6 ), // rgb 173,216,230 LightBlue
  167. RGB( 0xF0, 0x80, 0x80 ), // rgb 240,128,128 LightCoral
  168. RGB( 0xE0, 0xFF, 0xFF ), // rgb 224,255,255 LightCyan
  169. RGB( 0xFA, 0xFA, 0xD2 ), // rgb 250,250,210 LightGoldenrodYellow
  170. RGB( 0x90, 0xEE, 0x90 ), // rgb 144,238,144 LightGreen
  171. RGB( 0xD3, 0xD3, 0xD3 ), // rgb 211,211,211 LightGrey
  172. RGB( 0xFF, 0xB6, 0xC1 ), // rgb 255,182,193 LightPink
  173. RGB( 0xFF, 0xA0, 0x7A ), // rgb 255,160,122 LightSalmon
  174. RGB( 0x20, 0xB2, 0xAA ), // rgb 32,178,170 LightSeaGreen
  175. RGB( 0x87, 0xCE, 0xFA ), // rgb 135,206,250 LightSkyBlue
  176. RGB( 0x77, 0x88, 0x99 ), // rgb 119,136,153 LightSlateGray
  177. RGB( 0xB0, 0xC4, 0xDE ), // rgb 176,196,222 LightSteelBlue
  178. RGB( 0xFF, 0xFF, 0xE0 ), // rgb 255,255,224 LightYellow
  179. RGB( 0x00, 0xFF, 0x00 ), // rgb 0,255,0 Lime
  180. RGB( 0x32, 0xCD, 0x32 ), // rgb 50,205,50 LimeGreen
  181. RGB( 0xFA, 0xF0, 0xE6 ), // rgb 250,240,230 Linen
  182. RGB( 0xFF, 0x00, 0xFF ), // rgb 255,0,255 Magenta
  183. RGB( 0x80, 0x00, 0x00 ), // rgb 128,0,0 Maroon
  184. RGB( 0x66, 0xCD, 0xAA ), // rgb 102,205,170 MediumAquamarine
  185. RGB( 0x00, 0x00, 0xCD ), // rgb 0,0,205 MediumBlue
  186. RGB( 0xBA, 0x55, 0xD3 ), // rgb 186,85,211 MediumOrchid
  187. RGB( 0x93, 0x70, 0xDB ), // rgb 147,112,219 MediumPurple
  188. RGB( 0x3C, 0xB3, 0x71 ), // rgb 60,179,113 MediumSeaGreen
  189. RGB( 0x7B, 0x68, 0xEE ), // rgb 123,104,238 MediumSlateBlue
  190. RGB( 0x00, 0x00, 0xFA ), // rgb 0,0,154 MediumSpringGreen
  191. RGB( 0x48, 0xD1, 0xCC ), // rgb 72,209,204 MediumTurquoise
  192. RGB( 0xC7, 0x15, 0x85 ), // rgb 199,21,133 MediumVioletRed
  193. RGB( 0x19, 0x19, 0x70 ), // rgb 25,25,112 MidnightBlue
  194. RGB( 0xF5, 0xFF, 0xFA ), // rgb 245,255,250 MintCream
  195. RGB( 0xFF, 0xE4, 0xE1 ), // rgb 255,228,225 MistyRose
  196. RGB( 0xFF, 0xE4, 0xB5 ), // rgb 255,228,181 Moccasin
  197. RGB( 0xFF, 0xDE, 0xAD ), // rgb 255,222,173 NavajoWhite
  198. RGB( 0x00, 0x00, 0x80 ), // rgb 0,0,128 Navy
  199. RGB( 0xFD, 0xF5, 0xE6 ), // rgb 253,245,230 OldLace
  200. RGB( 0x80, 0x80, 0x00 ), // rgb 128,128,0 Olive
  201. RGB( 0x6B, 0x8E, 0x23 ), // rgb 107,142,35 OliveDrab
  202. RGB( 0xFF, 0xA5, 0x00 ), // rgb 255,165,0 Orange
  203. RGB( 0xFF, 0x45, 0x00 ), // rgb 255,69,0 OrangeRed
  204. RGB( 0xDA, 0x70, 0xD6 ), // rgb 218,112,214 Orchid
  205. RGB( 0xEE, 0xE8, 0xAA ), // rgb 238,232,170 PaleGoldenrod
  206. RGB( 0x98, 0xFB, 0x98 ), // rgb 152,251,152 PaleGreen
  207. RGB( 0xAF, 0xEE, 0xEE ), // rgb 175,238,238 PaleTurquoise
  208. RGB( 0xDB, 0x70, 0x93 ), // rgb 219,112,147 PaleVioletRed
  209. RGB( 0xFF, 0xEF, 0xD5 ), // rgb 255,239,213 PapayaWhip
  210. RGB( 0xFF, 0xDA, 0xB9 ), // rgb 255,218,185 PeachPuff
  211. RGB( 0xCD, 0x85, 0x3F ), // rgb 205,133,63 Peru
  212. RGB( 0xFF, 0xC0, 0xCB ), // rgb 255,192,203 Pink
  213. RGB( 0xDD, 0xA0, 0xDD ), // rgb 221,160,221 Plum
  214. RGB( 0xB0, 0xE0, 0xE6 ), // rgb 176,224,230 PowderBlue
  215. RGB( 0x80, 0x00, 0x80 ), // rgb 128,0,128 Purple
  216. RGB( 0xFF, 0x00, 0x00 ), // rgb 255,0,0 Red
  217. RGB( 0xBC, 0x8F, 0x8F ), // rgb 188,143,143 RosyBrown
  218. RGB( 0x41, 0x69, 0xE1 ), // rgb 65,105,225 RoyalBlue
  219. RGB( 0x8B, 0x45, 0x13 ), // rgb 139,69,19 SaddleBrown
  220. RGB( 0xFA, 0x80, 0x72 ), // rgb 250,128,114 Salmon
  221. RGB( 0xF4, 0xA4, 0x60 ), // rgb 244,164,96 SandyBrown
  222. RGB( 0x2E, 0x8B, 0x57 ), // rgb 46,139,87 SeaGreen
  223. RGB( 0xFF, 0xF5, 0xEE ), // rgb 255,245,238 Seashell
  224. RGB( 0xA0, 0x52, 0x2D ), // rgb 160,82,45 Sienna
  225. RGB( 0xC0, 0xC0, 0xC0 ), // rgb 192,192,192 Silver
  226. RGB( 0x87, 0xCE, 0xEB ), // rgb 135,206,235 SkyBlue
  227. RGB( 0x6A, 0x5A, 0xCD ), // rgb 106,90,205 SlateBlue
  228. RGB( 0x70, 0x80, 0x90 ), // rgb 112,128,144 SlateGray
  229. RGB( 0xFF, 0xFA, 0xFA ), // rgb 255,250,250 Snow
  230. RGB( 0x00, 0xFF, 0x7F ), // rgb 0,255,127 SpringGreen
  231. RGB( 0x46, 0x82, 0xB4 ), // rgb 70,130,180 SteelBlue
  232. RGB( 0xD2, 0xB4, 0x8C ), // rgb 210,180,140 Tan
  233. RGB( 0x00, 0x80, 0x80 ), // rgb 0,128,128 Teal
  234. RGB( 0xD8, 0xBF, 0xD8 ), // rgb 216,191,216 Thistle
  235. RGB( 0xFF, 0x63, 0x47 ), // rgb 255,99,71 Tomato
  236. RGB( 0x40, 0xE0, 0xD0 ), // rgb 64,224,208 Turquoise
  237. RGB( 0xEE, 0x82, 0xEE ), // rgb 238,130,238 Violet
  238. RGB( 0xF5, 0xDE, 0xB3 ), // rgb 245,222,179 Wheat
  239. RGB( 0xFF, 0xFF, 0xFF ), // rgb 255,255,255 White
  240. RGB( 0xF5, 0xF5, 0xF5 ), // rgb 245,245,245 WhiteSmoke
  241. RGB( 0xFF, 0xFF, 0x00 ), // rgb 255,255,0 Yellow
  242. RGB( 0x9A, 0xCD, 0x32 ) // rgb 154,205,50 YellowGreen
  243. };
  244. BSTR BStrFromStringResource( HINSTANCE hInstance, UINT id, WORD langid, LCID & lcid );
  245. CDict::CDict()
  246. {
  247. IMETHOD( CDict );
  248. for (int i = 0;i < ARRAYSIZE( g_Terms ); i++)
  249. {
  250. m_mapDictionary[*g_Terms[i].pTermID] = &g_Terms[i];
  251. m_mapMnemonicDictionary[g_Terms[i].pszMnemonic] = &g_Terms[i];
  252. }
  253. }
  254. CDict::~CDict()
  255. {
  256. IMETHOD( ~CDict );
  257. if( m_hinstResDll )
  258. FreeLibrary( m_hinstResDll );
  259. }
  260. HRESULT STDMETHODCALLTYPE
  261. CDict::GetLocalizedString (
  262. REFGUID Term,
  263. LCID lcid,
  264. BSTR * pResult,
  265. LCID * plcid
  266. )
  267. {
  268. IMETHOD( GetLocalizedString );
  269. *plcid = lcid;
  270. const DictMap::iterator it = m_mapDictionary.find(Term);
  271. if (it == m_mapDictionary.end())
  272. {
  273. *pResult = NULL;
  274. }
  275. else
  276. {
  277. const TermInfo pInfo = *it->second;
  278. *pResult = BStrFromStringResource( m_hinstResDll,
  279. STR_RESOURCE_OFFSET + pInfo.idString,
  280. LANGIDFROMLCID( lcid ),
  281. *plcid );
  282. }
  283. return S_OK;
  284. }
  285. HRESULT STDMETHODCALLTYPE
  286. CDict::GetParentTerm (
  287. REFGUID Term,
  288. GUID * pParentTerm
  289. )
  290. {
  291. IMETHOD( GetParentTerm );
  292. const DictMap::iterator it = m_mapDictionary.find(Term);
  293. if (it == m_mapDictionary.end())
  294. {
  295. *pParentTerm = GUID_NULL;
  296. }
  297. else
  298. {
  299. const TermInfo pInfo = *it->second;
  300. *pParentTerm = *pInfo.pParentID;
  301. }
  302. return S_OK;
  303. }
  304. HRESULT STDMETHODCALLTYPE
  305. CDict::GetMnemonicString (
  306. REFGUID Term,
  307. BSTR * pResult
  308. )
  309. {
  310. IMETHOD( GetMnemonicString );
  311. const DictMap::iterator it = m_mapDictionary.find(Term);
  312. if (it == m_mapDictionary.end())
  313. {
  314. *pResult = NULL;
  315. }
  316. else
  317. {
  318. const TermInfo pInfo = *it->second;
  319. *pResult = SysAllocString( pInfo.pszMnemonic );
  320. }
  321. return S_OK;
  322. }
  323. HRESULT STDMETHODCALLTYPE
  324. CDict::LookupMnemonicTerm (
  325. BSTR bstrMnemonic,
  326. GUID * pTerm
  327. )
  328. {
  329. IMETHOD( LookupMnemonicTerm );
  330. const DictMnemonicMap::iterator it = m_mapMnemonicDictionary.find(bstrMnemonic);
  331. if (it == m_mapMnemonicDictionary.end())
  332. {
  333. *pTerm = GUID_NULL;
  334. }
  335. else
  336. {
  337. const TermInfo pInfo = *it->second;
  338. *pTerm = *pInfo.pTermID;
  339. }
  340. return S_OK;
  341. }
  342. HRESULT STDMETHODCALLTYPE
  343. CDict::ConvertValueToString (
  344. REFGUID Term,
  345. LCID lcid,
  346. VARIANT varValue,
  347. BSTR * pbstrResult,
  348. LCID * plcid
  349. )
  350. {
  351. IMETHOD( ConvertValue );
  352. *plcid = lcid;
  353. const DictMap::iterator it = m_mapDictionary.find(Term);
  354. if (it == m_mapDictionary.end())
  355. {
  356. *pbstrResult = NULL;
  357. }
  358. else
  359. {
  360. const TermInfo pInfo = *it->second;
  361. *pbstrResult = (this->*pInfo.mfpConvertToString)( varValue, *plcid );
  362. }
  363. return S_OK;
  364. }
  365. // Methods Convert????ToString are called by ConvertValueToString via a
  366. // member funtion pointer in the TerInfo struct that is stored in the map
  367. BSTR CDict::ConvertPtsToString( const VARIANT & value, LCID & lcid )
  368. {
  369. TCHAR data[5];
  370. // see if we using metric
  371. GetLocaleInfo( lcid, LOCALE_IMEASURE, data, ARRAYSIZE( data ) );
  372. WCHAR result[16];
  373. // convert to centementers or inches
  374. if ( lstrcmp( data, TEXT("0") ) == 0 )
  375. {
  376. swprintf( result, L"%.2f", value.lVal / 72.0 * 2.54 );
  377. wcscat(result, L" cm" );
  378. }
  379. else
  380. {
  381. swprintf( result, L"%.2f", value.lVal / 72.0 );
  382. wcscat(result, L" in" );
  383. }
  384. return SysAllocString( result );
  385. }
  386. BSTR CDict::ConvertBoolToString( const VARIANT & value, LCID & lcid )
  387. {
  388. const WORD lang = LANGIDFROMLCID( lcid );
  389. if ( value.boolVal )
  390. return BStrFromStringResource( m_hinstResDll, STR_BOOL_TRUE, lang, lcid );
  391. else
  392. return BStrFromStringResource( m_hinstResDll, STR_BOOL_FALSE, lang, lcid );
  393. }
  394. BSTR CDict::ConvertColorToString( const VARIANT & value, LCID & lcid )
  395. {
  396. const COLORREF cr = value.lVal;
  397. double MinDistance = 450.0; // larger than the max distance
  398. int color;
  399. // Go thru all the colors we have names for and find the closest one
  400. for ( int i = 0; i < ARRAYSIZE( g_ColorArray ); i++ )
  401. {
  402. double distance = ColorDistance( cr, g_ColorArray[i] );
  403. if ( distance <= MinDistance )
  404. {
  405. MinDistance = distance;
  406. color = i;
  407. if ( distance == 0.0 )
  408. break;
  409. }
  410. }
  411. return BStrFromStringResource( m_hinstResDll,
  412. STR_COLOR_RESOURCE_OFFSET + color,
  413. LANGIDFROMLCID( lcid ),
  414. lcid );
  415. }
  416. BSTR CDict::ConvertWeightToString( const VARIANT & value, LCID & lcid )
  417. {
  418. _ASSERTE( ( (value.lVal / 100) < 9 ) && ( (value.lVal / 100) ) > 0 );
  419. return BStrFromStringResource( m_hinstResDll,
  420. STR_WEIGHT_RESOURCE_OFFSET + (value.lVal / 100),
  421. LANGIDFROMLCID( lcid ),
  422. lcid );
  423. }
  424. BSTR CDict::ConvertLangIDToString( const VARIANT & value, LCID & lcid )
  425. {
  426. TCHAR data[128];
  427. GetLocaleInfo( lcid, LOCALE_SLANGUAGE, data, ARRAYSIZE( data ) );
  428. return T2BSTR(data);
  429. }
  430. BSTR CDict::ConvertBSTRToString( const VARIANT & value, LCID & lcid )
  431. {
  432. return value.bstrVal;
  433. }
  434. // Distance is calculated the same as 3 dimensional cartesion distance.
  435. // This will find how far away the two colors are
  436. double CDict::ColorDistance(COLORREF crColor1, COLORREF crColor2)
  437. {
  438. DWORD dwDeltaRed;
  439. DWORD dwDeltaGreen;
  440. DWORD dwDeltaBlue;
  441. double dfDistance;
  442. dwDeltaRed = abs(GetRValue(crColor1) - GetRValue(crColor2));
  443. dwDeltaGreen = abs(GetGValue(crColor1) - GetGValue(crColor2));
  444. dwDeltaBlue = abs(GetBValue(crColor1) - GetBValue(crColor2));
  445. dfDistance = sqrt(dwDeltaRed * dwDeltaRed + dwDeltaGreen * dwDeltaGreen + dwDeltaBlue * dwDeltaBlue);
  446. return dfDistance;
  447. }
  448. BOOL CALLBACK EnumResLangProc( HINSTANCE hModule,
  449. LPCTSTR lpszType,
  450. LPCTSTR lpszName,
  451. WORD wIDLanguage,
  452. LONG_PTR lParam )
  453. {
  454. WORD Langid = *( WORD * )lParam;
  455. if ( Langid == wIDLanguage )
  456. {
  457. *( WORD * )lParam = 0; // indicate we found it
  458. return FALSE;
  459. }
  460. if ( PRIMARYLANGID( Langid ) == PRIMARYLANGID( wIDLanguage ) )
  461. *( WORD * )lParam = wIDLanguage;
  462. return TRUE;
  463. }
  464. /*
  465. * BStrFromStringResource
  466. *
  467. * See KB Q196899 for details on how this works.
  468. * A problem with LoadStringW is that it returns NULL on 9x - even
  469. * though the string is available as UNICODE in the resource file.
  470. *
  471. * (Another problem with LoadString is that there's no way
  472. * to determine the length of the string in advance, so you have
  473. * to guess the length of buffer to allocate.)
  474. * This technique uses Find/Load/LockResource to get to the
  475. * string in memory, and creates the BSTR direcly from that.
  476. *
  477. */
  478. BSTR BStrFromStringResource( HINSTANCE hInstance, UINT id )
  479. {
  480. LCID lcid;
  481. // MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) causes lang associted with calling thread to be used...
  482. return BStrFromStringResource( hInstance, id, LANGIDFROMLCID( GetThreadLocale() ), lcid );
  483. }
  484. BSTR BStrFromStringResource( HINSTANCE hInstance, UINT id, WORD lcid, LCID & Actuallcid)
  485. {
  486. // String resources are stored in blocks of 16,
  487. // with the resource ID being the string ID / 16.
  488. // See KB Q196899 for more information.
  489. UINT block = (id >> 4) + 1; // Compute block number.
  490. UINT offset = id & 0xf; // Compute offset into block.
  491. WORD langid = LANGIDFROMLCID( lcid );
  492. WORD RealLangid = langid;
  493. WORD SortID = SORTIDFROMLCID( lcid );
  494. // Make sure the language they want in in the resource file
  495. // if not use the one the matches the best
  496. EnumResourceLanguages( hInstance, RT_STRING, MAKEINTRESOURCE( block ), EnumResLangProc, ( DWORD_PTR )&RealLangid );
  497. if ( RealLangid )
  498. {
  499. // if the language they asked for is not in the resource file use the language of the thread
  500. if ( RealLangid == langid )
  501. {
  502. WORD ThreadLang = LANGIDFROMLCID( GetThreadLocale() );
  503. SortID = SORT_DEFAULT;
  504. RealLangid = ThreadLang;
  505. EnumResourceLanguages( hInstance,
  506. RT_STRING,
  507. MAKEINTRESOURCE( block ),
  508. EnumResLangProc,
  509. ( DWORD_PTR )&RealLangid );
  510. if ( RealLangid == ThreadLang )
  511. return NULL; // we can't find any language that makes sence
  512. if ( RealLangid == 0 )
  513. RealLangid = LANGIDFROMLCID( ThreadLang );
  514. }
  515. Actuallcid = MAKELCID( RealLangid, SortID );
  516. }
  517. else // we found it
  518. {
  519. RealLangid = langid;
  520. Actuallcid = lcid;
  521. }
  522. HRSRC hrsrc = FindResourceEx( hInstance, RT_STRING, MAKEINTRESOURCE( block ), langid );
  523. if( ! hrsrc )
  524. {
  525. DWORD err = GetLastError();
  526. // this is here until I figure out why FindResourceEx does not work
  527. hrsrc = FindResource( hInstance, MAKEINTRESOURCE( block ), RT_STRING );
  528. if( ! hrsrc )
  529. return NULL;
  530. }
  531. HGLOBAL hglobal = LoadResource( hInstance, hrsrc );
  532. if( ! hglobal )
  533. return NULL;
  534. LPWSTR pstr = (LPWSTR) LockResource( hglobal );
  535. if( ! pstr )
  536. return NULL;
  537. // Block contains 16 [<len><string...>] pairs.
  538. // Skip over as many strings (using the len header) as needed...
  539. for( UINT i = 0; i < offset; i++ )
  540. {
  541. pstr += *pstr + 1;
  542. }
  543. // Got the string we want - now use it to create a BStr.
  544. // (Note that the string is not NUL-terminated - but it
  545. // does have a length prefix, so we use that instead.)
  546. return SysAllocStringLen( pstr + 1, *pstr );
  547. }