weight_derivation.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function IsCJK_Unified_Ideographs(ACodePoint : Cardinal) : Boolean;inline;
  2. begin
  3. Result := (ACodePoint >= $4E00) and (ACodePoint <= $9FFF); // $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 IsTangut(ACodePoint : Cardinal) : Boolean;inline;
  10. begin
  11. Result := (ACodePoint >= $17000) and (ACodePoint <= $187FF);
  12. end;
  13. function IsTangutComponent(ACodePoint : Cardinal) : Boolean;inline;
  14. begin
  15. Result := (ACodePoint >= $18800) and (ACodePoint <= $18AFF);
  16. end;
  17. function IsTangutSupplement(ACodePoint : Cardinal) : Boolean;inline;
  18. begin
  19. Result := (ACodePoint >= $18D00) and (ACodePoint <= $18D7F);
  20. end;
  21. procedure DeriveWeightTangut(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);inline;
  22. begin
  23. AResult[0].Weights[0] := Word($FB00);
  24. AResult[0].Weights[1] := $20;
  25. AResult[0].Weights[2] := $2;
  26. AResult[1].Weights[0] := (ACodePoint - $17000) or $8000;
  27. AResult[1].Weights[1] := 0;
  28. AResult[1].Weights[2] := 0;
  29. end;
  30. function IsNushu(ACodePoint : Cardinal) : Boolean;inline;
  31. begin
  32. Result := (ACodePoint >= $1B170) and (ACodePoint <= $1B2FF);
  33. end;
  34. function IsKhitanSmallScript(ACodePoint : Cardinal) : Boolean;inline;
  35. begin
  36. Result := (ACodePoint >= $18B00) and (ACodePoint <= $18CFF);
  37. end;
  38. procedure DeriveWeightNushu(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);inline;
  39. begin
  40. AResult[0].Weights[0] := Word($FB01);
  41. AResult[0].Weights[1] := $20;
  42. AResult[0].Weights[2] := $2;
  43. AResult[1].Weights[0] := (ACodePoint - $1B170) or $8000;
  44. AResult[1].Weights[1] := 0;
  45. AResult[1].Weights[2] := 0;
  46. end;
  47. procedure DeriveWeightKhitanSmallScript(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);inline;
  48. begin
  49. AResult[0].Weights[0] := Word($FB02);
  50. AResult[0].Weights[1] := $20;
  51. AResult[0].Weights[2] := $2;
  52. AResult[1].Weights[0] := (ACodePoint - $18B00) or $8000;
  53. AResult[1].Weights[1] := 0;
  54. AResult[1].Weights[2] := 0;
  55. end;
  56. {$IFDEF UNI_BUILD_TIME}
  57. function isUnifiedIdeograph(const ACodePoint : Cardinal; const AUnifiedIdeographs : TCodePointRecArray) : boolean;
  58. begin
  59. Result := IsIncluded(ACodePoint,AUnifiedIdeographs);
  60. end;
  61. {$ENDIF UNI_BUILD_TIME}
  62. {$IFNDEF UNI_BUILD_TIME}
  63. function isUnifiedIdeograph(const ACodePoint : Cardinal) : boolean;
  64. var
  65. p : PUC_Prop;
  66. begin
  67. p := GetProps(ACodePoint);
  68. Result := (p <> nil) and p^.UnifiedIdeograph;
  69. end;
  70. {$ENDIF UNI_BUILD_TIME}
  71. procedure DeriveWeight(
  72. const ACodePoint : Cardinal;
  73. AResult : PUCA_PropWeights
  74. {$IFDEF UNI_BUILD_TIME}
  75. ;const AUnifiedIdeographs : TCodePointRecArray
  76. {$ENDIF UNI_BUILD_TIME}
  77. );
  78. const
  79. BASE_1 = Word($FB40);
  80. BASE_2 = Word($FB80);
  81. BASE_3 = Word($FBC0);
  82. var
  83. base : Word;
  84. ui : boolean;
  85. begin
  86. if IsTangut(ACodePoint) or
  87. IsTangutComponent(ACodePoint) or
  88. IsTangutSupplement(ACodePoint)
  89. then begin
  90. DeriveWeightTangut(ACodePoint,AResult);
  91. end else if IsNushu(ACodePoint) then begin
  92. DeriveWeightNushu(ACodePoint,AResult);
  93. end else if IsKhitanSmallScript(ACodePoint) then begin
  94. DeriveWeightKhitanSmallScript(ACodePoint,AResult);
  95. end else begin
  96. ui := isUnifiedIdeograph(ACodePoint{$IFDEF UNI_BUILD_TIME},AUnifiedIdeographs{$ENDIF UNI_BUILD_TIME});
  97. if ui and
  98. (IsCJK_Unified_Ideographs(ACodePoint) or IsCJK_Compatibility_Ideographs(ACodePoint))
  99. then begin
  100. base := BASE_1
  101. end else if ui and
  102. not(IsCJK_Unified_Ideographs(ACodePoint) or IsCJK_Compatibility_Ideographs(ACodePoint))
  103. then begin
  104. base := BASE_2
  105. end else begin
  106. base := BASE_3;
  107. end;
  108. AResult[0].Weights[0] := base + (ACodePoint shr 15);
  109. AResult[0].Weights[1] := $20;
  110. AResult[0].Weights[2] := $2;
  111. AResult[1].Weights[0] := (ACodePoint and $7FFF) or $8000;
  112. AResult[1].Weights[1] := 0;
  113. AResult[1].Weights[2] := 0;
  114. end;
  115. end;