FontMetadata.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {
  2. FreedrawIcon,
  3. FontFamilyNormalIcon,
  4. FontFamilyHeadingIcon,
  5. FontFamilyCodeIcon,
  6. } from "../components/icons";
  7. import { FONT_FAMILY, FONT_FAMILY_FALLBACKS } from "../constants";
  8. /**
  9. * Encapsulates font metrics with additional font metadata.
  10. * */
  11. export interface FontMetadata {
  12. /** for head & hhea metrics read the woff2 with https://fontdrop.info/ */
  13. metrics: {
  14. /** head.unitsPerEm metric */
  15. unitsPerEm: 1000 | 1024 | 2048;
  16. /** hhea.ascender metric */
  17. ascender: number;
  18. /** hhea.descender metric */
  19. descender: number;
  20. /** harcoded unitless line-height, https://github.com/excalidraw/excalidraw/pull/6360#issuecomment-1477635971 */
  21. lineHeight: number;
  22. };
  23. /** element to be displayed as an icon */
  24. icon?: JSX.Element;
  25. /** flag to indicate a deprecated font */
  26. deprecated?: true;
  27. /** flag to indicate a server-side only font */
  28. serverSide?: true;
  29. /** flag to indiccate a local-only font */
  30. local?: true;
  31. /** flag to indicate a fallback font */
  32. fallback?: true;
  33. }
  34. export const FONT_METADATA: Record<number, FontMetadata> = {
  35. [FONT_FAMILY.Excalifont]: {
  36. metrics: {
  37. unitsPerEm: 1000,
  38. ascender: 886,
  39. descender: -374,
  40. lineHeight: 1.25,
  41. },
  42. icon: FreedrawIcon,
  43. },
  44. [FONT_FAMILY.Nunito]: {
  45. metrics: {
  46. unitsPerEm: 1000,
  47. ascender: 1011,
  48. descender: -353,
  49. lineHeight: 1.35,
  50. },
  51. icon: FontFamilyNormalIcon,
  52. },
  53. [FONT_FAMILY["Lilita One"]]: {
  54. metrics: {
  55. unitsPerEm: 1000,
  56. ascender: 923,
  57. descender: -220,
  58. lineHeight: 1.15,
  59. },
  60. icon: FontFamilyHeadingIcon,
  61. },
  62. [FONT_FAMILY["Comic Shanns"]]: {
  63. metrics: {
  64. unitsPerEm: 1000,
  65. ascender: 750,
  66. descender: -250,
  67. lineHeight: 1.25,
  68. },
  69. icon: FontFamilyCodeIcon,
  70. },
  71. [FONT_FAMILY.Virgil]: {
  72. metrics: {
  73. unitsPerEm: 1000,
  74. ascender: 886,
  75. descender: -374,
  76. lineHeight: 1.25,
  77. },
  78. icon: FreedrawIcon,
  79. deprecated: true,
  80. },
  81. [FONT_FAMILY.Helvetica]: {
  82. metrics: {
  83. unitsPerEm: 2048,
  84. ascender: 1577,
  85. descender: -471,
  86. lineHeight: 1.15,
  87. },
  88. icon: FontFamilyNormalIcon,
  89. deprecated: true,
  90. local: true,
  91. },
  92. [FONT_FAMILY.Cascadia]: {
  93. metrics: {
  94. unitsPerEm: 2048,
  95. ascender: 1900,
  96. descender: -480,
  97. lineHeight: 1.2,
  98. },
  99. icon: FontFamilyCodeIcon,
  100. deprecated: true,
  101. },
  102. [FONT_FAMILY["Liberation Sans"]]: {
  103. metrics: {
  104. unitsPerEm: 2048,
  105. ascender: 1854,
  106. descender: -434,
  107. lineHeight: 1.15,
  108. },
  109. serverSide: true,
  110. },
  111. [FONT_FAMILY_FALLBACKS.Xiaolai]: {
  112. metrics: {
  113. unitsPerEm: 1000,
  114. ascender: 880,
  115. descender: -144,
  116. lineHeight: 1.15,
  117. },
  118. fallback: true,
  119. },
  120. [FONT_FAMILY_FALLBACKS["Segoe UI Emoji"]]: {
  121. metrics: {
  122. // reusing Excalifont metrics
  123. unitsPerEm: 1000,
  124. ascender: 886,
  125. descender: -374,
  126. lineHeight: 1.25,
  127. },
  128. local: true,
  129. fallback: true,
  130. },
  131. };
  132. /** Unicode ranges defined by google fonts */
  133. export const GOOGLE_FONTS_RANGES = {
  134. LATIN:
  135. "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD",
  136. LATIN_EXT:
  137. "U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF",
  138. CYRILIC_EXT:
  139. "U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F",
  140. CYRILIC: "U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116",
  141. VIETNAMESE:
  142. "U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB",
  143. };
  144. /** local protocol to skip the local font from registering or inlining */
  145. export const LOCAL_FONT_PROTOCOL = "local:";