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.

123 lines
2.4 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module HYPH.CPP -- Hyphenation class |
  5. *
  6. * A table which holds the non-standard hyphenation cases. We store
  7. * these entries in the table because we cache the results of hyphenation
  8. * in our CLine structure, storing the actual WCHAR and khyph would cost
  9. * 4 bytes. With this mechanism we can use 5 bits.
  10. *
  11. *
  12. * Several elements are reserved:
  13. * 0 - No hyphenation
  14. * 1 - Normal hyphenation
  15. * 2 - Delete before
  16. *
  17. * All other ones contain a khyph and a WCHAR.
  18. * If performance is an issue, this table could be sorted and binary
  19. * searched. We assume this table typically has few entries in use.
  20. *
  21. * Owner:<nl>
  22. * Keith Curtis: Created
  23. *
  24. * Copyright (c) 1995-1999, Microsoft Corporation. All rights reserved.
  25. */
  26. #include <_common.h>
  27. #include <_array.h>
  28. #include <_hyph.h>
  29. const int chyphReserved = 3;
  30. extern CHyphCache *g_phc;
  31. void FreeHyphCache(void)
  32. {
  33. delete g_phc;
  34. }
  35. /*
  36. * CHyphCache::Add (khyph, chHyph)
  37. *
  38. * @mfunc
  39. * Adds a new special hyphenation entry to the cache
  40. *
  41. * @rdesc
  42. * ihyph to be used
  43. */
  44. int CHyphCache::Add(UINT khyph, WCHAR chHyph)
  45. {
  46. HYPHENTRY he;
  47. he.khyph = khyph;
  48. he.chHyph = chHyph;
  49. HYPHENTRY *phe;
  50. if (phe = CArray<HYPHENTRY>::Add(1, NULL))
  51. {
  52. *phe = he;
  53. return Count() + chyphReserved - 1;
  54. }
  55. return 1; //If we run out of memory, just do normal hyphenation
  56. }
  57. /*
  58. * CHyphCache::Find(khyph, chHyph)
  59. *
  60. * @mfunc
  61. * Finds a special hyphenation entry in the cache.
  62. * If it doesn't exist, then it will add it.
  63. *
  64. * @rdesc
  65. * index into table if successful, FALSE if failed
  66. */
  67. int CHyphCache::Find(UINT khyph, WCHAR chHyph)
  68. {
  69. HYPHENTRY *phe = Elem(0);
  70. //Special cases
  71. if (khyph <= khyphNormal)
  72. return khyph;
  73. if (khyph == khyphDeleteBefore)
  74. return 2;
  75. for (int ihyph = 0; ihyph < Count(); ihyph++, phe++)
  76. {
  77. if (chHyph == phe->chHyph && phe->khyph == khyph)
  78. return ihyph + chyphReserved;
  79. }
  80. //Not found, so add
  81. return Add(khyph, chHyph);
  82. }
  83. /*
  84. * CHyphCache::GetAt(iHyph, khyph, chHyph)
  85. *
  86. * @mfunc
  87. * Given an ihyph as stored in the CLine array, fill in
  88. * the khyph and the chHyph
  89. *
  90. * @rdesc
  91. * void
  92. */
  93. void CHyphCache::GetAt(int ihyph, UINT & khyph, WCHAR & chHyph)
  94. {
  95. Assert(ihyph - chyphReserved < Count());
  96. //Special cases
  97. if (ihyph <= 2)
  98. {
  99. chHyph = 0;
  100. if (ihyph <= khyphNormal)
  101. khyph = ihyph;
  102. if (ihyph == 2)
  103. khyph = khyphDeleteBefore;
  104. return;
  105. }
  106. ihyph -= chyphReserved;
  107. HYPHENTRY *phe = Elem(ihyph);
  108. khyph = phe->khyph;
  109. chHyph = phe->chHyph;
  110. return;
  111. }