weight_derivation.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. function IsCJK_Unified_Ideographs(ACodePoint : Cardinal) : Boolean;inline;
  2. begin
  3. Result := (ACodePoint >= $4E00) and (ACodePoint <= $9FCC); // $9FFF
  4. end;
  5. function IsCJK_Compatibility_Ideographs(ACodePoint : Cardinal) : Boolean;inline;
  6. begin
  7. Result := (ACodePoint >= $F900) and (ACodePoint <= $FAFF);
  8. end;
  9. function IsCJK_Unified_Ideographs_Extension_A(ACodePoint : Cardinal) : Boolean;inline;
  10. begin
  11. Result := (ACodePoint >= $3400) and (ACodePoint <= $4DB5); // $4DBF
  12. end;
  13. function IsCJK_Unified_Ideographs_Extension_B(ACodePoint : Cardinal) : Boolean;inline;
  14. begin
  15. Result := (ACodePoint >= $20000) and (ACodePoint <= $2A6D6); // $2A6DF
  16. end;
  17. function IsCJK_Unified_Ideographs_Extension_C(ACodePoint : Cardinal) : Boolean;inline;
  18. begin
  19. Result := (ACodePoint >= $2A700) and (ACodePoint <= $2B734); // $2B73F
  20. end;
  21. function IsCJK_Unified_Ideographs_Extension_D(ACodePoint : Cardinal) : Boolean;inline;
  22. begin
  23. Result := (ACodePoint >= $2B740) and (ACodePoint <= $2B81D); // $2B81F
  24. end;
  25. function IsCJK_Compatibility_Ideographs_Supplement(ACodePoint : Cardinal) : Boolean;inline;
  26. begin
  27. Result := (ACodePoint >= $2F800) and (ACodePoint <= $2FA1F);
  28. end;
  29. function IsTangut(ACodePoint : Cardinal) : Boolean;inline;
  30. begin
  31. Result := (ACodePoint >= $17000) and (ACodePoint <= $187FF);
  32. end;
  33. function IsTangutComponent(ACodePoint : Cardinal) : Boolean;inline;
  34. begin
  35. Result := (ACodePoint >= $18800) and (ACodePoint <= $18AFF);
  36. end;
  37. procedure DeriveWeightTangut(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);inline;
  38. begin
  39. AResult[0].Weights[0] := Word($FB00);
  40. AResult[0].Weights[1] := $20;
  41. AResult[0].Weights[2] := $2;
  42. AResult[1].Weights[0] := (ACodePoint - $17000) or $8000;
  43. AResult[1].Weights[1] := 0;
  44. AResult[1].Weights[2] := 0;
  45. end;
  46. procedure DeriveWeight(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);
  47. const
  48. BASE_1 = Word($FB40);
  49. BASE_2 = Word($FB80);
  50. BASE_3 = Word($FBC0);
  51. var
  52. base : Word;
  53. begin
  54. if IsTangut(ACodePoint) or IsTangutComponent(ACodePoint) then begin
  55. DeriveWeightTangut(ACodePoint,AResult);
  56. end else begin
  57. if IsCJK_Unified_Ideographs(ACodePoint) or IsCJK_Compatibility_Ideographs(ACodePoint) then
  58. base := BASE_1
  59. else if IsCJK_Unified_Ideographs_Extension_A(ACodePoint) or
  60. IsCJK_Unified_Ideographs_Extension_B(ACodePoint) or
  61. IsCJK_Unified_Ideographs_Extension_C(ACodePoint) or
  62. IsCJK_Unified_Ideographs_Extension_D(ACodePoint) or
  63. IsCJK_Compatibility_Ideographs_Supplement(ACodePoint)
  64. then begin
  65. base := BASE_2;
  66. end else begin
  67. base := BASE_3;
  68. end;
  69. AResult[0].Weights[0] := base + (ACodePoint shr 15);
  70. AResult[0].Weights[1] := $20;
  71. AResult[0].Weights[2] := $2;
  72. AResult[1].Weights[0] := (ACodePoint and $7FFF) or $8000;
  73. AResult[1].Weights[1] := 0;
  74. AResult[1].Weights[2] := 0;
  75. end;
  76. end;