Leaked source code of windows server 2003
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.

974 lines
29 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module clasifyc.cpp -- Kinsoku classify characters |
  5. *
  6. * Used in word breaking procs, particularly important
  7. * for properly wrapping a line.
  8. *
  9. * Authors: <nl>
  10. * Jon Matousek
  11. *
  12. * Copyright (c) 1995-1998 Microsoft Corporation. All rights reserved.
  13. */
  14. #include "_common.h"
  15. #include "_clasfyc.h"
  16. #include "_array.h"
  17. ASSERTDATA
  18. // Data for Kinsoku character classifications.
  19. // NOTE: All values are for UNICODE characters.
  20. // "dumb" quotes and other characters with no left/right orientation.
  21. // This is a hack-around the Kinsoku rules, these are treated
  22. // like an opening paren, when leading and kind of like a closing
  23. // paren when follow--but will only break on white space in former case.
  24. #define brkclsQuote 0
  25. #define C3_FullWidth (C3_KATAKANA | C3_HIRAGANA | C3_IDEOGRAPH | C3_FULLWIDTH)
  26. const WCHAR set0[] = {
  27. 0x0022, // QUOTATION MARK
  28. 0x0027, // APOSTROPHE
  29. 0x2019, // RIGHT SINGLE QUOTATION MARK
  30. 0x301F, // LOW DOUBLE PRIME QUOTATION MARK
  31. 0xFF02, // FULLWIDTH QUOTATION MARK
  32. 0xFF07, // FULLWIDTH APOSTROPHE
  33. 0
  34. };
  35. // Opening-parenthesis character
  36. #define brkclsOpen 1
  37. const WCHAR set1[] = {
  38. 0x0028, // LEFT PARENTHESIS
  39. 0x003C, // LEFT ANGLE BRACKET
  40. 0x005B, // LEFT SQUARE BRACKET
  41. 0x007B, // LEFT CURLY BRACKET
  42. 0x00AB, // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
  43. 0x2018, // LEFT SINGLE QUOTATION MARK
  44. 0x201C, // LEFT DOUBLE QUOTATION MARK
  45. 0x2039, // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
  46. 0x2045, // LEFT SQUARE BRACKET WITH QUILL
  47. 0x207D, // SUPERSCRIPT LEFT PARENTHESIS
  48. 0x208D, // SUBSCRIPT LEFT PARENTHESIS
  49. 0x3008, // LEFT ANGLE BRACKET
  50. 0x300A, // LEFT DOUBLE ANGLE BRACKET
  51. 0x300C, // LEFT CORNER BRACKET
  52. 0x300E, // LEFT WHITE CORNER BRACKET
  53. 0x3010, // LEFT BLACK LENTICULAR BRACKET
  54. 0x3014, // LEFT TORTOISE SHELL BRACKET
  55. 0x3016, // LEFT WHITE LENTICULAR BRACKET
  56. 0x3018, // LEFT WHITE TORTOISE SHELL BRACKET
  57. 0x301A, // LEFT WHITE SQUARE BRACKET
  58. 0x301D, // REVERSED DOUBLE PRIME QUOTATION MARK
  59. 0xFD3E, // ORNATE LEFT PARENTHESIS
  60. 0xFE59, // SMALL LEFT PARENTHESIS
  61. 0xFE5B, // SMALL LEFT CURLY BRACKET
  62. 0xFE5D, // SMALL LEFT TORTOISE SHELL BRACKET
  63. 0xFF08, // FULLWIDTH LEFT PARENTHESIS
  64. 0xFF3B, // FULLWIDTH LEFT SQUARE BRACKET
  65. 0xFF5B, // FULLWIDTH LEFT CURLY BRACKET
  66. 0xFF62, // HALFWIDTH LEFT CORNER BRACKET
  67. 0xFFE9, // HALFWIDTH LEFTWARDS ARROW
  68. 0
  69. };
  70. // Closing-parenthesis character
  71. #define brkclsClose 2
  72. const WCHAR set2[] = {
  73. // 0x002C, // COMMA moved to set 6 to conjoin numerals.
  74. 0x002D, // HYPHEN
  75. 0x00AD, // OPTIONAL HYPHEN
  76. 0x055D, // ARMENIAN COMMA
  77. 0x060C, // ARABIC COMMA
  78. 0x3001, // IDEOGRAPHIC COMMA
  79. 0xFE50, // SMALL COMMA
  80. 0xFE51, // SMALL IDEOGRAPHIC COMMA
  81. 0xFF0C, // FULLWIDTH COMMA
  82. 0xFF64, // HALFWIDTH IDEOGRAPHIC COMMA
  83. 0x0029, // RIGHT PARENTHESIS
  84. 0x003E, // RIGHT ANGLE BRACKET
  85. 0x005D, // RIGHT SQUARE BRACKET
  86. 0x007D, // RIGHT CURLY BRACKET
  87. 0x00BB, // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
  88. //0x2019, // RIGHT SINGLE QUOTATION MARK moved to set 0
  89. 0x201D, // RIGHT DOUBLE QUOTATION MARK
  90. 0x203A, // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
  91. 0x2046, // RIGHT SQUARE BRACKET WITH QUILL
  92. 0x207E, // SUPERSCRIPT RIGHT PARENTHESIS
  93. 0x208E, // SUBSCRIPT RIGHT PARENTHESIS
  94. 0x3009, // RIGHT ANGLE BRACKET
  95. 0x300B, // RIGHT DOUBLE ANGLE BRACKET
  96. 0x300D, // RIGHT CORNER BRACKET
  97. 0x300F, // RIGHT WHITE CORNER BRACKET
  98. 0x3011, // RIGHT BLACK LENTICULAR BRACKET
  99. 0x3015, // RIGHT TORTOISE SHELL BRACKET
  100. 0x3017, // RIGHT WHITE LENTICULAR BRACKET
  101. 0x3019, // RIGHT WHITE TORTOISE SHELL BRACKET
  102. 0x301B, // RIGHT WHITE SQUARE BRACKET
  103. 0x301E, // DOUBLE PRIME QUOTATION MARK
  104. 0xFD3F, // ORNATE RIGHT PARENTHESIS
  105. 0xFE5A, // SMALL RIGHT PARENTHESIS
  106. 0xFE5C, // SMALL RIGHT CURLY BRACKET
  107. 0xFE5E, // SMALL RIGHT TORTOISE SHELL BRACKET
  108. 0xFF09, // FULLWIDTH RIGHT PARENTHESIS
  109. 0xFF3D, // FULLWIDTH RIGHT SQUARE BRACKET
  110. 0xFF5D, // FULLWIDTH RIGHT CURLY BRACKET
  111. 0xFF63, // HALFWIDTH RIGHT CORNER BRACKET
  112. 0xFFEB, // HALFWIDTH RIGHTWARDS ARROW
  113. 0
  114. };
  115. // 'Non-breaking' em-character at line-starting point
  116. #define brkclsGlueA 3
  117. const WCHAR set3[] = {
  118. 0x3005, // IDEOGRAPHIC ITERATION MARK
  119. 0x309D, // HIRAGANA ITERATION MARK
  120. 0x309E, // HIRAGANA VOICED ITERATION MARK
  121. 0x30FC, // KATAKANA-HIRAGANA PROLONGED SOUND MARK
  122. 0x30FD, // KATAKANA ITERATION MARK
  123. 0x30FE, // KATAKANA VOICED ITERATION MARK
  124. 0x3041, // HIRAGANA LETTER SMALL A
  125. 0x3043, // HIRAGANA LETTER SMALL I
  126. 0x3045, // HIRAGANA LETTER SMALL U
  127. 0x3047, // HIRAGANA LETTER SMALL E
  128. 0x3049, // HIRAGANA LETTER SMALL O
  129. 0x3063, // HIRAGANA LETTER SMALL TU
  130. 0x3083, // HIRAGANA LETTER SMALL YA
  131. 0x3085, // HIRAGANA LETTER SMALL YU
  132. 0x3087, // HIRAGANA LETTER SMALL YO
  133. 0x308E, // HIRAGANA LETTER SMALL WA
  134. 0x309B, // KATAKANA-HIRAGANA VOICED SOUND MARK
  135. 0x309C, // KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
  136. 0x30A1, // KATAKANA LETTER SMALL A
  137. 0x30A3, // KATAKANA LETTER SMALL I
  138. 0x30A5, // KATAKANA LETTER SMALL U
  139. 0x30A7, // KATAKANA LETTER SMALL E
  140. 0x30A9, // KATAKANA LETTER SMALL O
  141. 0x30C3, // KATAKANA LETTER SMALL TU
  142. 0x30E3, // KATAKANA LETTER SMALL YA
  143. 0x30E5, // KATAKANA LETTER SMALL YU
  144. 0x30E7, // KATAKANA LETTER SMALL YO
  145. 0x30EE, // KATAKANA LETTER SMALL WA
  146. 0x30F5, // KATAKANA LETTER SMALL KA
  147. 0x30F6, // KATAKANA LETTER SMALL KE
  148. 0xFF67, // HALFWIDTH KATAKANA LETTER SMALL A
  149. 0xFF68, // HALFWIDTH KATAKANA LETTER SMALL I
  150. 0xFF69, // HALFWIDTH KATAKANA LETTER SMALL U
  151. 0xFF6A, // HALFWIDTH KATAKANA LETTER SMALL E
  152. 0xFF6B, // HALFWIDTH KATAKANA LETTER SMALL O
  153. 0xFF6C, // HALFWIDTH KATAKANA LETTER SMALL YA
  154. 0xFF6D, // HALFWIDTH KATAKANA LETTER SMALL YU
  155. 0xFF6E, // HALFWIDTH KATAKANA LETTER SMALL YO
  156. 0xFF6F, // HALFWIDTH KATAKANA LETTER SMALL TU
  157. 0xFF70, // HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK
  158. 0xFF9E, // HALFWIDTH KATAKANA VOICED SOUND MARK
  159. 0xFF9F, // HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
  160. 0
  161. };
  162. // Expression mark
  163. #define brkclsExclaInterr 4
  164. const WCHAR set4[] = {
  165. 0x0021, // EXCLAMATION MARK
  166. 0x003F, // QUESTION MARK
  167. 0x00A1, // INVERTED EXCLAMATION MARK
  168. 0x00BF, // INVERTED QUESTION MARK
  169. 0x01C3, // LATIN LETTER RETROFLEX CLICK
  170. 0x037E, // GREEK QUESTION MARK
  171. 0x055C, // ARMENIAN EXCLAMATION MARK
  172. 0x055E, // ARMENIAN QUESTION MARK
  173. 0x055F, // ARMENIAN ABBREVIATION MARK
  174. 0x061F, // ARABIC QUESTION MARK
  175. 0x203C, // DOUBLE EXCLAMATION MARK
  176. 0x203D, // INTERROBANG
  177. 0x2762, // HEAVY EXCLAMATION MARK ORNAMENT
  178. 0x2763, // HEAVY HEART EXCLAMATION MARK ORNAMENT
  179. 0xFE56, // SMALL QUESTION MARK
  180. 0xFE57, // SMALL EXCLAMATION MARK
  181. 0xFF01, // FULLWIDTH EXCLAMATION MARK
  182. 0xFF1F, // FULLWIDTH QUESTION MARK
  183. 0
  184. };
  185. // Centered punctuation mark
  186. const WCHAR set5[] = {
  187. // 0x003A, // COLON moved to set 6 to conjoin numerals.
  188. // 0x003B, // SEMICOLON moved to set 6 to conjoin numerals
  189. 0x00B7, // MIDDLE DOT
  190. 0x30FB, // KATAKANA MIDDLE DOT
  191. 0xFF65, // HALFWIDTH KATAKANA MIDDLE DOT
  192. 0x061B, // ARABIC SEMICOLON
  193. 0xFE54, // SMALL SEMICOLON
  194. 0xFE55, // SMALL COLON
  195. 0xFF1A, // FULLWIDTH COLON
  196. 0xFF1B, // FULLWIDTH SEMICOLON
  197. 0
  198. };
  199. // Punctuation mark // diverged from the Kinsoku tables to enhance
  200. #define brkclsSlash 6
  201. const WCHAR set6[] = { // How colon, comma, and full stop are treated around
  202. 0x002C, // COMMA // numerals and set 15 (roman text).
  203. 0x002f, // SLASH // But don't break up URLs (see IsURLDelimiter())!
  204. 0x003A, // COLON
  205. 0x003B, // SEMICOLON
  206. 0x002E, // FULL STOP (PERIOD)
  207. 0x0589, // ARMENIAN FULL STOP
  208. 0x06D4, // ARABIC FULL STOP
  209. 0x3002, // IDEOGRAPHIC FULL STOP
  210. 0xFE52, // SMALL FULL STOP
  211. 0xFF0E, // FULLWIDTH FULL STOP
  212. 0xFF61, // HALFWIDTH IDEOGRAPHIC FULL STOP
  213. 0
  214. };
  215. // Inseparable character
  216. #define brkclsInseparable 7
  217. const WCHAR set7[] = {
  218. 0 // FUTURE (alexgo): maybe handle these.
  219. };
  220. // Pre-numeral abbreviation
  221. #define brkclsPrefix 8
  222. const WCHAR set8[] = {
  223. 0x0024, // DOLLAR SIGN
  224. 0x00A3, // POUND SIGN
  225. 0x00A4, // CURRENCY SIGN
  226. 0x00A5, // YEN SIGN
  227. 0x005C, // REVERSE SOLIDUS (looks like Yen in FE fonts.)
  228. 0x0E3F, // THAI CURRENCY SYMBOL BAHT
  229. 0x20AC, // EURO-CURRENCY SIGN
  230. 0x20A1, // COLON SIGN
  231. 0x20A2, // CRUZEIRO SIGN
  232. 0x20A3, // FRENCH FRANC SIGN
  233. 0x20A4, // LIRA SIGN
  234. 0x20A5, // MILL SIGN
  235. 0x20A6, // NAIRA SIGN
  236. 0x20A7, // PESETA SIGN
  237. 0x20A8, // RUPEE SIGN
  238. 0x20A9, // WON SIGN
  239. 0x20AA, // NEW SHEQEL SIGN
  240. 0xFF04, // FULLWIDTH DOLLAR SIGN
  241. 0xFFE5, // FULLWIDTH YEN SIGN
  242. 0xFFE6, // FULLWIDTH WON SIGN
  243. 0xFFE1, // FULLWIDTH POUND SIGN
  244. 0
  245. };
  246. // Post-numeral abbreviation
  247. #define brkclsPostfix 9
  248. const WCHAR set9[] = {
  249. 0x00A2, // CENT SIGN
  250. 0x00B0, // DEGREE SIGN
  251. 0x2103, // DEGREE CELSIUS
  252. 0x2109, // DEGREE FAHRENHEIT
  253. 0x212A, // KELVIN SIGN
  254. 0x0025, // PERCENT SIGN
  255. 0x066A, // ARABIC PERCENT SIGN
  256. 0xFE6A, // SMALL PERCENT SIGN
  257. 0xFF05, // FULLWIDTH PERCENT SIGN
  258. 0x2030, // PER MILLE SIGN
  259. 0x2031, // PER TEN THOUSAND SIGN
  260. 0x2032, // PRIME
  261. 0x2033, // DOUBLE PRIME
  262. 0x2034, // TRIPLE PRIME
  263. 0x2035, // REVERSED PRIME
  264. 0x2036, // REVERSED DOUBLE PRIME
  265. 0x2037, // REVERSED TRIPLE PRIME
  266. 0xFF05, // FULLWIDTH PERCENT SIGN
  267. 0xFFE0, // FULLWIDTH CENT SIGN
  268. 0
  269. };
  270. // Japanese space (blank) character
  271. #define brkclsNoStartIdeo 10
  272. const WCHAR set10[] = {
  273. 0x3000, // IDEOGRAPHIC SPACE
  274. 0
  275. };
  276. // Japanese characters other than above
  277. #define brkclsIdeographic 11
  278. const WCHAR set11[] = {
  279. 0 //we use GetStringTypeEx
  280. };
  281. // Characters included in numeral-sequence
  282. #define brkclsNumeral 12
  283. const WCHAR set12[] = {
  284. 0x0030, // DIGIT ZERO
  285. 0x0031, // DIGIT ONE
  286. 0x0032, // DIGIT TWO
  287. 0x0033, // DIGIT THREE
  288. 0x0034, // DIGIT FOUR
  289. 0x0035, // DIGIT FIVE
  290. 0x0036, // DIGIT SIX
  291. 0x0037, // DIGIT SEVEN
  292. 0x0038, // DIGIT EIGHT
  293. 0x0039, // DIGIT NINE
  294. 0x0660, // ARABIC-INDIC DIGIT ZERO
  295. 0x0661, // ARABIC-INDIC DIGIT ONE
  296. 0x0662, // ARABIC-INDIC DIGIT TWO
  297. 0x0663, // ARABIC-INDIC DIGIT THREE
  298. 0x0664, // ARABIC-INDIC DIGIT FOUR
  299. 0x0665, // ARABIC-INDIC DIGIT FIVE
  300. 0x0666, // ARABIC-INDIC DIGIT SIX
  301. 0x0667, // ARABIC-INDIC DIGIT SEVEN
  302. 0x0668, // ARABIC-INDIC DIGIT EIGHT
  303. 0x0669, // ARABIC-INDIC DIGIT NINE
  304. 0x06F0, // EXTENDED ARABIC-INDIC DIGIT ZERO
  305. 0x06F1, // EXTENDED ARABIC-INDIC DIGIT ONE
  306. 0x06F2, // EXTENDED ARABIC-INDIC DIGIT TWO
  307. 0x06F3, // EXTENDED ARABIC-INDIC DIGIT THREE
  308. 0x06F4, // EXTENDED ARABIC-INDIC DIGIT FOUR
  309. 0x06F5, // EXTENDED ARABIC-INDIC DIGIT FIVE
  310. 0x06F6, // EXTENDED ARABIC-INDIC DIGIT SIX
  311. 0x06F7, // EXTENDED ARABIC-INDIC DIGIT SEVEN
  312. 0x06F8, // EXTENDED ARABIC-INDIC DIGIT EIGHT
  313. 0x06F9, // EXTENDED ARABIC-INDIC DIGIT NINE
  314. 0x0966, // DEVANAGARI DIGIT ZERO
  315. 0x0967, // DEVANAGARI DIGIT ONE
  316. 0x0968, // DEVANAGARI DIGIT TWO
  317. 0x0969, // DEVANAGARI DIGIT THREE
  318. 0x096A, // DEVANAGARI DIGIT FOUR
  319. 0x096B, // DEVANAGARI DIGIT FIVE
  320. 0x096C, // DEVANAGARI DIGIT SIX
  321. 0x096D, // DEVANAGARI DIGIT SEVEN
  322. 0x096E, // DEVANAGARI DIGIT EIGHT
  323. 0x096F, // DEVANAGARI DIGIT NINE
  324. 0x09E6, // BENGALI DIGIT ZERO
  325. 0x09E7, // BENGALI DIGIT ONE
  326. 0x09E8, // BENGALI DIGIT TWO
  327. 0x09E9, // BENGALI DIGIT THREE
  328. 0x09EA, // BENGALI DIGIT FOUR
  329. 0x09EB, // BENGALI DIGIT FIVE
  330. 0x09EC, // BENGALI DIGIT SIX
  331. 0x09ED, // BENGALI DIGIT SEVEN
  332. 0x09EE, // BENGALI DIGIT EIGHT
  333. 0x09EF, // BENGALI DIGIT NINE
  334. 0x0A66, // GURMUKHI DIGIT ZERO
  335. 0x0A67, // GURMUKHI DIGIT ONE
  336. 0x0A68, // GURMUKHI DIGIT TWO
  337. 0x0A69, // GURMUKHI DIGIT THREE
  338. 0x0A6A, // GURMUKHI DIGIT FOUR
  339. 0x0A6B, // GURMUKHI DIGIT FIVE
  340. 0x0A6C, // GURMUKHI DIGIT SIX
  341. 0x0A6D, // GURMUKHI DIGIT SEVEN
  342. 0x0A6E, // GURMUKHI DIGIT EIGHT
  343. 0x0A6F, // GURMUKHI DIGIT NINE
  344. 0x0AE6, // GUJARATI DIGIT ZERO
  345. 0x0AE7, // GUJARATI DIGIT ONE
  346. 0x0AE8, // GUJARATI DIGIT TWO
  347. 0x0AE9, // GUJARATI DIGIT THREE
  348. 0x0AEA, // GUJARATI DIGIT FOUR
  349. 0x0AEB, // GUJARATI DIGIT FIVE
  350. 0x0AEC, // GUJARATI DIGIT SIX
  351. 0x0AED, // GUJARATI DIGIT SEVEN
  352. 0x0AEE, // GUJARATI DIGIT EIGHT
  353. 0x0AEF, // GUJARATI DIGIT NINE
  354. 0x0B66, // ORIYA DIGIT ZERO
  355. 0x0B67, // ORIYA DIGIT ONE
  356. 0x0B68, // ORIYA DIGIT TWO
  357. 0x0B69, // ORIYA DIGIT THREE
  358. 0x0B6A, // ORIYA DIGIT FOUR
  359. 0x0B6B, // ORIYA DIGIT FIVE
  360. 0x0B6C, // ORIYA DIGIT SIX
  361. 0x0B6D, // ORIYA DIGIT SEVEN
  362. 0x0B6E, // ORIYA DIGIT EIGHT
  363. 0x0B6F, // ORIYA DIGIT NINE
  364. 0x0BE7, // TAMIL DIGIT ONE
  365. 0x0BE8, // TAMIL DIGIT TWO
  366. 0x0BE9, // TAMIL DIGIT THREE
  367. 0x0BEA, // TAMIL DIGIT FOUR
  368. 0x0BEB, // TAMIL DIGIT FIVE
  369. 0x0BEC, // TAMIL DIGIT SIX
  370. 0x0BED, // TAMIL DIGIT SEVEN
  371. 0x0BEE, // TAMIL DIGIT EIGHT
  372. 0x0BEF, // TAMIL DIGIT NINE
  373. 0x0BF0, // TAMIL NUMBER TEN
  374. 0x0BF1, // TAMIL NUMBER ONE HUNDRED
  375. 0x0BF2, // TAMIL NUMBER ONE THOUSAND
  376. 0x0C66, // TELUGU DIGIT ZERO
  377. 0x0C67, // TELUGU DIGIT ONE
  378. 0x0C68, // TELUGU DIGIT TWO
  379. 0x0C69, // TELUGU DIGIT THREE
  380. 0x0C6A, // TELUGU DIGIT FOUR
  381. 0x0C6B, // TELUGU DIGIT FIVE
  382. 0x0C6C, // TELUGU DIGIT SIX
  383. 0x0C6D, // TELUGU DIGIT SEVEN
  384. 0x0C6E, // TELUGU DIGIT EIGHT
  385. 0x0C6F, // TELUGU DIGIT NINE
  386. 0x0CE6, // KANNADA DIGIT ZERO
  387. 0x0CE7, // KANNADA DIGIT ONE
  388. 0x0CE8, // KANNADA DIGIT TWO
  389. 0x0CE9, // KANNADA DIGIT THREE
  390. 0x0CEA, // KANNADA DIGIT FOUR
  391. 0x0CEB, // KANNADA DIGIT FIVE
  392. 0x0CEC, // KANNADA DIGIT SIX
  393. 0x0CED, // KANNADA DIGIT SEVEN
  394. 0x0CEE, // KANNADA DIGIT EIGHT
  395. 0x0CEF, // KANNADA DIGIT NINE
  396. 0x0D66, // MALAYALAM DIGIT ZERO
  397. 0x0D67, // MALAYALAM DIGIT ONE
  398. 0x0D68, // MALAYALAM DIGIT TWO
  399. 0x0D69, // MALAYALAM DIGIT THREE
  400. 0x0D6A, // MALAYALAM DIGIT FOUR
  401. 0x0D6B, // MALAYALAM DIGIT FIVE
  402. 0x0D6C, // MALAYALAM DIGIT SIX
  403. 0x0D6D, // MALAYALAM DIGIT SEVEN
  404. 0x0D6E, // MALAYALAM DIGIT EIGHT
  405. 0x0D6F, // MALAYALAM DIGIT NINE
  406. 0x0E50, // THAI DIGIT ZERO
  407. 0x0E51, // THAI DIGIT ONE
  408. 0x0E52, // THAI DIGIT TWO
  409. 0x0E53, // THAI DIGIT THREE
  410. 0x0E54, // THAI DIGIT FOUR
  411. 0x0E55, // THAI DIGIT FIVE
  412. 0x0E56, // THAI DIGIT SIX
  413. 0x0E57, // THAI DIGIT SEVEN
  414. 0x0E58, // THAI DIGIT EIGHT
  415. 0x0E59, // THAI DIGIT NINE
  416. 0x0ED0, // LAO DIGIT ZERO
  417. 0x0ED1, // LAO DIGIT ONE
  418. 0x0ED2, // LAO DIGIT TWO
  419. 0x0ED3, // LAO DIGIT THREE
  420. 0x0ED4, // LAO DIGIT FOUR
  421. 0x0ED5, // LAO DIGIT FIVE
  422. 0x0ED6, // LAO DIGIT SIX
  423. 0x0ED7, // LAO DIGIT SEVEN
  424. 0x0ED8, // LAO DIGIT EIGHT
  425. 0x0ED9, // LAO DIGIT NINE
  426. 0xFF10, // FULLWIDTH DIGIT ZERO
  427. 0xFF11, // FULLWIDTH DIGIT ONE
  428. 0xFF12, // FULLWIDTH DIGIT TWO
  429. 0xFF13, // FULLWIDTH DIGIT THREE
  430. 0xFF14, // FULLWIDTH DIGIT FOUR
  431. 0xFF15, // FULLWIDTH DIGIT FIVE
  432. 0xFF16, // FULLWIDTH DIGIT SIX
  433. 0xFF17, // FULLWIDTH DIGIT SEVEN
  434. 0xFF18, // FULLWIDTH DIGIT EIGHT
  435. 0xFF19, // FULLWIDTH DIGIT NINE
  436. 0x3007, // IDEOGRAPHIC NUMBER ZERO
  437. 0x3021, // HANGZHOU NUMERAL ONE
  438. 0x3022, // HANGZHOU NUMERAL TWO
  439. 0x3023, // HANGZHOU NUMERAL THREE
  440. 0x3024, // HANGZHOU NUMERAL FOUR
  441. 0x3025, // HANGZHOU NUMERAL FIVE
  442. 0x3026, // HANGZHOU NUMERAL SIX
  443. 0x3027, // HANGZHOU NUMERAL SEVEN
  444. 0x3028, // HANGZHOU NUMERAL EIGHT
  445. 0x3029, // HANGZHOU NUMERAL NINE
  446. 0
  447. };
  448. // Characters included in unit symbol group
  449. const WCHAR set13[] = {
  450. 0 //we use GetStringTypeEx
  451. };
  452. //Roman inter-word space
  453. #define brkclsSpaceN 14
  454. const WCHAR set14[] = {
  455. 0x0009, // TAB
  456. 0x0020, // SPACE
  457. 0x2002, // EN SPACE
  458. 0x2003, // EM SPACE
  459. 0x2004, // THREE-PER-EM SPACE
  460. 0x2005, // FOUR-PER-EM SPACE
  461. 0x2006, // SIX-PER-EM SPACE
  462. 0x2007, // FIGURE SPACE
  463. 0x2008, // PUNCTUATION SPACE
  464. 0x2009, // THIN SPACE
  465. 0x200A, // HAIR SPACE
  466. 0x200B, // ZERO WIDTH SPACE
  467. WCH_EMBEDDING, // OBJECT EMBEDDING (0xFFFC)
  468. 0
  469. };
  470. // Roman characters
  471. #define brkclsAlpha 15
  472. const WCHAR set15[] = {
  473. 0 //we use GetStringTypeEx
  474. };
  475. // So we can easily loop over all Kinsoku categories.
  476. const WCHAR *charCategories[] = {
  477. set0,
  478. set1,
  479. set2,
  480. set3,
  481. set4,
  482. set5,
  483. set6,
  484. set7,
  485. set8,
  486. set9,
  487. set10,
  488. set11,
  489. set12,
  490. set13,
  491. set14,
  492. set15
  493. };
  494. static const INT classifyChunkSize = 64;
  495. static const INT indexSize = 65536 / classifyChunkSize;
  496. static const INT classifyBitMapSize = indexSize / 8;
  497. static const INT bitmapShift = 6; // 16 - log(indexSize)/log(2)
  498. typedef struct {
  499. CHAR classifications[classifyChunkSize]; // must be unsigned bytes!
  500. } ClassifyChunk;
  501. static ClassifyChunk *classifyData; // Chunk array, sparse chrs
  502. static BYTE *classifyIndex; // Indexes into chunk array
  503. /*
  504. * BOOL InitKinsokuClassify()
  505. *
  506. * @func
  507. * Map the static character tables into a compact array for
  508. * quick lookup of the characters Kinsoku classification.
  509. *
  510. * @comm
  511. * Kinsoku classification is necessary for word breaking and
  512. * may be neccessary for proportional line layout, Kinsoku style.
  513. *
  514. * @devnote
  515. * We break the entire Unicode range in to chunks of characters.
  516. * Not all of the chunks will have data in them. We do not
  517. * maintain information on empty chunks, therefore we create
  518. * a compact, contiguous array of chunks for only the chunks
  519. * that do contain information. We prepend 1 empty chunk to the
  520. * beginning of this array, where all of the empty chunks map to,
  521. * this prevents a contiontional test on NULL data. The lookup
  522. * will return 0 for any character not in the tables, so the client
  523. * will then need to process the character further in such cases.
  524. *
  525. * @rdesc
  526. * return TRUE if we successfully created the lookup table.
  527. */
  528. BOOL InitKinsokuClassify()
  529. {
  530. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "InitKinsokuClassify");
  531. WORD bitMapKey; // For calcing total chunks
  532. BYTE bitData; // For calcing total chunks
  533. WCHAR ch;
  534. LPCWSTR pWChar; // Looping over char sets.
  535. INT i, j, count; // Loop support.
  536. BYTE classifyBitMap[classifyBitMapSize], // Temp bitmap.
  537. *pIndex; // Index into chunk array.
  538. // See how many chunks we'll need. We loop over all of the special
  539. // characters
  540. AssertSz(cKinsokuCategories == ARRAY_SIZE(charCategories),
  541. "InitKinsokuClassify: incorrect Kinsoku-category count");
  542. ZeroMemory(classifyBitMap, sizeof(classifyBitMap));
  543. for (i = 0; i < cKinsokuCategories; i++ )
  544. {
  545. pWChar = charCategories[i];
  546. while ( ch = *pWChar++ )
  547. {
  548. bitMapKey = ch >> bitmapShift;
  549. classifyBitMap[bitMapKey >> 3] |= 1 << (bitMapKey & 7);
  550. }
  551. }
  552. // Now that we know how many chunks we'll need, allocate the memory.
  553. count = 1 + CountMatchingBits((DWORD *)classifyBitMap, (DWORD *)classifyBitMap, sizeof(classifyBitMap)/sizeof(DWORD));
  554. classifyData = (ClassifyChunk *) PvAlloc( sizeof(ClassifyChunk) * count, GMEM_ZEROINIT);
  555. classifyIndex = (BYTE *) PvAlloc( sizeof(BYTE) * indexSize, GMEM_ZEROINIT);
  556. // We failed if we did not get the memory.
  557. if ( !classifyData || !classifyIndex )
  558. return FALSE; // FAILED.
  559. // Set Default missing value.
  560. FillMemory( classifyData, -1, sizeof(ClassifyChunk) * count );
  561. // Init the pointers to the chunks, which are really just indexes into
  562. // a contiguous block of memory -- an one-based array of chunks.
  563. pIndex = classifyIndex;
  564. count = 1; // 1 based array.
  565. for (i = 0; i < sizeof(classifyBitMap); i++ ) // Loop over all bytes.
  566. { // Get the bitmap data.
  567. bitData = classifyBitMap[i]; // For each bit in the byte
  568. for (j = 0; j < 8; j++, bitData >>= 1, pIndex++)
  569. {
  570. if(bitData & 1)
  571. *pIndex = count++; // We used a chunk.
  572. }
  573. }
  574. // Store the classifications of each character.
  575. // Note: classifications are 1 based, a zero value
  576. // means the category was not set.
  577. for (i = 0; i < cKinsokuCategories; i++ )
  578. {
  579. pWChar = charCategories[i]; // Loop over all chars in
  580. while ( ch = *pWChar++ ) // category.
  581. {
  582. bitMapKey = ch >> bitmapShift;
  583. Assert( classifyIndex[bitMapKey] > 0 );
  584. Assert( classifyIndex[bitMapKey] < count );
  585. classifyData[classifyIndex[bitMapKey]].
  586. classifications[ ch & ( classifyChunkSize-1 )] = (char)i;
  587. }
  588. }
  589. return TRUE; // Successfully created.
  590. }
  591. void UninitKinsokuClassify()
  592. {
  593. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "UninitKinsokuClassify");
  594. FreePv(classifyData);
  595. FreePv(classifyIndex);
  596. }
  597. /*
  598. * KinsokuClassify(ch)
  599. *
  600. * @func
  601. * Kinsoku classify the character iff it was a given from
  602. * one of the classification tables.
  603. *
  604. * @comm
  605. * Hi order bits of ch are used to get an index value used to index
  606. * into an array of chunks. Each chunk contains the classifications
  607. * for that character as well as some number of characters adjacent
  608. * to that character. The low order bits are used to index into
  609. * the chunk of adjacent characters.
  610. *
  611. * @devnote
  612. * Because of the way we constructed the array, all that we need to
  613. * do is look up the data; no conditionals necessary.
  614. *
  615. * The routine is inline to avoid the call overhead. It is static
  616. * because it only returns characters from the tables; i.e., this
  617. * routine does NOT classify all Unicode characters.
  618. *
  619. * @rdesc
  620. * Returns the classification.
  621. */
  622. static inline INT
  623. KinsokuClassify(
  624. WCHAR ch ) // @parm char to classify.
  625. {
  626. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "KinsokuClassify");
  627. return classifyData[ classifyIndex[ ch >> bitmapShift ] ].
  628. classifications[ ch & ( classifyChunkSize-1 )];
  629. }
  630. #define IsSameNonFEClass(_c1, _c2) (!(((_c1) ^ (_c2)) & WBF_CLASS))
  631. #define IdeoKanaTypes (C3_HALFWIDTH | C3_FULLWIDTH | C3_KATAKANA | C3_HIRAGANA)
  632. #define IdeoTypes (IdeoKanaTypes | C3_IDEOGRAPH)
  633. #define IsIdeographic(_c1) ( 0 != (_c1 & (C3_KATAKANA | C3_HIRAGANA | C3_IDEOGRAPH)) )
  634. /*
  635. * IsSameClass(currType1, startType1, currType3, startType3 )
  636. *
  637. * @func Used to determine word breaks.
  638. *
  639. * @comm Ideographic chars are all considered to be unique, so that only
  640. * one at a time is selected
  641. */
  642. BOOL IsSameClass(WORD currType1, WORD startType1,
  643. WORD currType3, WORD startType3 )
  644. {
  645. BOOL fIdeographic = IsIdeographic(currType3);
  646. // Do classifications for startType3 being ideographic
  647. if(IsIdeographic(startType3))
  648. {
  649. int checkTypes = (currType3 & IdeoTypes) ^ (startType3 & IdeoTypes);
  650. // We only get picky with non-ideographic Kana chars
  651. // C3_HALFWIDTH | C3_FULLWIDTH | C3_KATAKANA | C3_HIRAGANA.
  652. return fIdeographic && (startType3 & IdeoKanaTypes) &&
  653. (!checkTypes || checkTypes == C3_FULLWIDTH || checkTypes == C3_HIRAGANA ||
  654. checkTypes == (C3_FULLWIDTH | C3_HIRAGANA));
  655. }
  656. // Do classifications for nonideographic startType3
  657. return !fIdeographic && IsSameNonFEClass(currType1, startType1);
  658. }
  659. WORD ClassifyChar(TCHAR ch)
  660. {
  661. TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "ClassifyChar");
  662. WORD wRes;
  663. if (IsKorean(ch)) // special Korean class
  664. return WBF_KOREAN;
  665. if (IsThai(ch))
  666. return 0;
  667. if (ch == WCH_EMBEDDING) // Objects
  668. return 2 | WBF_BREAKAFTER;
  669. W32->GetStringTypeEx(LOCALE_SYSTEM_DEFAULT, CT_CTYPE1, &ch, 1, &wRes);
  670. if(wRes & C1_SPACE)
  671. {
  672. if(wRes & C1_BLANK) // Only TAB, BLANK, and
  673. { // nobreak BLANK are here
  674. if(ch == 0x20)
  675. return 2 | WBF_BREAKLINE | WBF_ISWHITE;
  676. if(ch == TAB)
  677. return 3 | WBF_ISWHITE;
  678. return 2 | WBF_ISWHITE;
  679. }
  680. if(ch == CELL)
  681. return 3 | WBF_ISWHITE;
  682. return 4 | WBF_ISWHITE;
  683. }
  684. if(wRes & C1_PUNCT && !IsDiacriticOrKashida(ch, 0))
  685. return ch == '-' ? (1 | WBF_BREAKAFTER) : 1;
  686. return 0;
  687. }
  688. /*
  689. * BatchClassify (pch, cch, pcType3, kinsokuClassifications, pwRes)
  690. *
  691. * @func
  692. * Kinsoku classify and ClassifyChar() each character of the given string.
  693. *
  694. * @comm
  695. * The Kinsoku classifications are passed to the CanBreak() routine. We
  696. * do process in batch to save on overhead.
  697. *
  698. * If the character is not in the Kinsoku classification tables then
  699. * GetStringTypeEx is used to classify any remaining character.
  700. *
  701. * @rdesc
  702. * Result in out param kinsokuClassifications.
  703. * pcType3 result from GetStringTypeEx for CT_CTYPE3
  704. */
  705. void BatchClassify (
  706. const WCHAR *pch, // @parm char string
  707. INT cch, // @parm Count of chars in string
  708. WORD *pcType3, // @parm Result of GetStringTypeEx for CT_CTYPE3
  709. INT * kinsokuClassifications, // @parm Result of the classifications
  710. WORD *pwRes) // @parm ClassifyChar() result
  711. {
  712. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "BatchClassify");
  713. WCHAR ch;
  714. WORD cType3;
  715. INT iCategory;
  716. WORD wRes;
  717. Assert( cch < MAX_CLASSIFY_CHARS );
  718. Assert( pch );
  719. Assert( kinsokuClassifications );
  720. // *Note* Using CT_CTYPE1 values alone is unreliable since CT_CTYPE1
  721. // defines C1_PUNCT for all diacritic characters. According to KDChang,
  722. // this is by design for POSIX compatibility and it couldn't be changed
  723. // easily since Win9x shares the same NLS data with NT. (wchao)
  724. // Therefore we use CT_CTYPE3 data to distinguish diacritics, except on
  725. // Win9x, for which we use a range check, since GetStringTypeExW isn't
  726. // supported).
  727. W32->GetStringTypes(0, pch, cch, pwRes, pcType3);
  728. while ( cch-- ) // For all ch...
  729. {
  730. wRes = *pwRes;
  731. ch = *pch++;
  732. if(IsKorean(ch))
  733. wRes = WBF_KOREAN; // Special Korean class
  734. else if (IsThai(ch))
  735. wRes = 0; // Thai class
  736. else if (ch == WCH_EMBEDDING) // Objects
  737. wRes = 2 | WBF_BREAKAFTER;
  738. else if(wRes & C1_SPACE)
  739. {
  740. if (wRes & C1_BLANK)
  741. {
  742. wRes = 2 | WBF_ISWHITE;
  743. if(ch == 0x20)
  744. wRes = 2 | WBF_BREAKLINE | WBF_ISWHITE;
  745. if(ch == TAB)
  746. wRes = 3 | WBF_ISWHITE;
  747. }
  748. else
  749. wRes = 4 | WBF_ISWHITE;
  750. }
  751. else if(ch == CELL)
  752. wRes = 3 | WBF_ISWHITE;
  753. else if((wRes & C1_PUNCT) && !IsDiacriticOrKashida(ch, *pcType3))
  754. wRes = ch == '-' ? (1 | WBF_BREAKAFTER) : 1;
  755. else
  756. wRes = 0;
  757. *pwRes++ = wRes;
  758. if(IsKorean(ch))
  759. iCategory = 11;
  760. else
  761. {
  762. iCategory = KinsokuClassify(ch);
  763. if(iCategory < 0) // If not classified
  764. { // then it is one of:
  765. cType3 = *pcType3;
  766. if(cType3 & C3_SYMBOL)
  767. iCategory = 13; // symbol chars,
  768. else if(cType3 & C3_FullWidth)
  769. iCategory = 11; // ideographic chars,
  770. else
  771. iCategory = 15; // all other chars.
  772. }
  773. }
  774. *kinsokuClassifications++ = iCategory;
  775. pcType3++;
  776. }
  777. }
  778. /*
  779. * GetKinsokuClass (ch)
  780. *
  781. * @func
  782. * Kinsoku classify ch
  783. *
  784. * @comm
  785. * The Kinsoku classifications are passed to the CanBreak() routine. This
  786. * single-character routine is for use with LineServices
  787. *
  788. * If the character is not in the Kinsoku classification tables then
  789. * GetStringTypeEx is used to classify any remaining character.
  790. *
  791. * @rdesc
  792. * Kinsoku classification for ch
  793. */
  794. INT GetKinsokuClass (
  795. WCHAR ch) // @parm char
  796. {
  797. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "GetKinsokuClassification");
  798. if(IsKorean(ch))
  799. return 11;
  800. // surrogate classification
  801. if (IN_RANGE(0xD800, ch, 0xDFFF))
  802. return IN_RANGE(0xDC00, ch, 0xDFFF) ? brkclsClose : brkclsOpen;
  803. INT iCategory = KinsokuClassify(ch);
  804. if(iCategory >= 0)
  805. return iCategory;
  806. WORD cType3;
  807. W32->GetStringTypeEx(0, CT_CTYPE3, &ch, 1, &cType3);
  808. if(cType3 & C3_SYMBOL)
  809. return 13; // Symbol chars
  810. if(cType3 & C3_FullWidth)
  811. return 11; // Ideographic chars
  812. return 15; // All other chars.
  813. }
  814. /*
  815. * CanBreak(class1, class2)
  816. *
  817. * @func
  818. * Look into the truth table to see if two consecutive charcters
  819. * can have a line break between them.
  820. *
  821. * @comm
  822. * This determines whether two successive characters can break a line.
  823. * The matrix is taken from JIS X4051 and is based on categorizing
  824. * characters into 15 classifications.
  825. *
  826. * @devnote
  827. * The table is 1 based.
  828. *
  829. * @rdesc
  830. * Returns TRUE if the characters can be broken across a line.
  831. */
  832. BOOL CanBreak(
  833. INT class1, //@parm Kinsoku classification of character #1
  834. INT class2 ) //@parm Kinsoku classification of following character.
  835. {
  836. TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "CanBreak");
  837. static const WORD br[16] = {// fedc ba98 7654 3210
  838. 0x0000, // 0 0000 0000 0000 0000
  839. 0x0000, // 1 0000 0000 0000 0000
  840. 0xfd82, // 2 1111 1101 1000 0010
  841. 0xfd82, // 3 1111 1101 1000 0010
  842. 0xfd82, // 4 1111 1101 1000 0010
  843. 0xfd82, // 5 1111 1101 1000 0010
  844. 0x6d82, // 6 0110 1101 1000 0010
  845. 0xfd02, // 7 1111 1101 0000 0010
  846. 0x0000, // 8 0000 0000 0000 0000
  847. 0xfd82, // 9 1111 1101 1000 0010
  848. 0xfd83, // a 1111 1101 1000 0011
  849. 0xfd82, // b 1111 1101 1000 0010
  850. 0x6d82, // c 0110 1101 1000 0010
  851. 0x5d82, // d 0101 1101 1000 0010
  852. 0xfd83, // e 1111 1101 1000 0011
  853. 0x4d82, // f 0100 1101 1000 0010
  854. };
  855. return (br[class1] >> class2) & 1;
  856. }
  857. /*
  858. * IsURLDelimiter(ch)
  859. *
  860. * @func
  861. * Punctuation characters are those of sets 0, 1, 2, 4, 5, and 6,
  862. * and < or > which we consider to be brackets, not "less" or
  863. * "greater" signs. On the other hand; "/" (in set 6) should not be
  864. * a delimiter, but rather a part of the URL.
  865. *
  866. * @comm This function is used in URL detection
  867. *
  868. * @rdesc
  869. * Returns TRUE if the character is a punctuation mark.
  870. */
  871. BOOL IsURLDelimiter(
  872. WCHAR ch)
  873. {
  874. if (IsKorean(ch))
  875. return TRUE;
  876. INT iset = KinsokuClassify(ch);
  877. return IN_RANGE(0, iset, 2) || (IN_RANGE(4, iset, 6) && ch != '/')
  878. || ch == '<' || ch == '>';
  879. }