weight_derivation.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. procedure DeriveWeight(const ACodePoint : Cardinal; AResult : PUCA_PropWeights);
  30. const
  31. BASE_1 = Word($FB40);
  32. BASE_2 = Word($FB80);
  33. BASE_3 = Word($FBC0);
  34. var
  35. base : Word;
  36. begin
  37. if IsCJK_Unified_Ideographs(ACodePoint) or IsCJK_Compatibility_Ideographs(ACodePoint) then
  38. base := BASE_1
  39. else if IsCJK_Unified_Ideographs_Extension_A(ACodePoint) or
  40. IsCJK_Unified_Ideographs_Extension_B(ACodePoint) or
  41. IsCJK_Unified_Ideographs_Extension_C(ACodePoint) or
  42. IsCJK_Unified_Ideographs_Extension_D(ACodePoint) or
  43. IsCJK_Compatibility_Ideographs_Supplement(ACodePoint)
  44. then begin
  45. base := BASE_2;
  46. end else begin
  47. base := BASE_3;
  48. end;
  49. AResult[0].Weights[0] := base + (ACodePoint shr 15);
  50. AResult[0].Weights[1] := $20;
  51. AResult[0].Weights[2] := $2;
  52. AResult[1].Weights[0] := (ACodePoint and $7FFF) or $8000;
  53. AResult[1].Weights[1] := 0;
  54. AResult[1].Weights[2] := 0;
  55. end;