TextFormatterImpl.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Avalonia.Media.TextFormatting.Unicode;
  5. using Avalonia.Utilities;
  6. namespace Avalonia.Media.TextFormatting
  7. {
  8. internal class TextFormatterImpl : TextFormatter
  9. {
  10. private static readonly char[] s_empty = { ' ' };
  11. /// <inheritdoc cref="TextFormatter.FormatLine"/>
  12. public override TextLine FormatLine(ITextSource textSource, int firstTextSourceIndex, double paragraphWidth,
  13. TextParagraphProperties paragraphProperties, TextLineBreak? previousLineBreak = null)
  14. {
  15. var textWrapping = paragraphProperties.TextWrapping;
  16. FlowDirection resolvedFlowDirection;
  17. TextLineBreak? nextLineBreak = null;
  18. List<DrawableTextRun> drawableTextRuns;
  19. var textRuns = FetchTextRuns(textSource, firstTextSourceIndex,
  20. out var textEndOfLine, out var textSourceLength);
  21. if (previousLineBreak?.RemainingRuns != null)
  22. {
  23. resolvedFlowDirection = previousLineBreak.FlowDirection;
  24. drawableTextRuns = previousLineBreak.RemainingRuns.ToList();
  25. nextLineBreak = previousLineBreak;
  26. }
  27. else
  28. {
  29. drawableTextRuns = ShapeTextRuns(textRuns, paragraphProperties, out resolvedFlowDirection);
  30. if (nextLineBreak == null && textEndOfLine != null)
  31. {
  32. nextLineBreak = new TextLineBreak(textEndOfLine, resolvedFlowDirection);
  33. }
  34. }
  35. TextLineImpl textLine;
  36. switch (textWrapping)
  37. {
  38. case TextWrapping.NoWrap:
  39. {
  40. textLine = new TextLineImpl(drawableTextRuns, firstTextSourceIndex, textSourceLength,
  41. paragraphWidth, paragraphProperties, resolvedFlowDirection, nextLineBreak);
  42. textLine.FinalizeLine();
  43. break;
  44. }
  45. case TextWrapping.WrapWithOverflow:
  46. case TextWrapping.Wrap:
  47. {
  48. textLine = PerformTextWrapping(drawableTextRuns, firstTextSourceIndex, paragraphWidth, paragraphProperties,
  49. resolvedFlowDirection, nextLineBreak);
  50. break;
  51. }
  52. default:
  53. throw new ArgumentOutOfRangeException(nameof(textWrapping));
  54. }
  55. return textLine;
  56. }
  57. /// <summary>
  58. /// Split a sequence of runs into two segments at specified length.
  59. /// </summary>
  60. /// <param name="textRuns">The text run's.</param>
  61. /// <param name="length">The length to split at.</param>
  62. /// <returns>The split text runs.</returns>
  63. internal static SplitResult<List<DrawableTextRun>> SplitDrawableRuns(List<DrawableTextRun> textRuns, int length)
  64. {
  65. var currentLength = 0;
  66. for (var i = 0; i < textRuns.Count; i++)
  67. {
  68. var currentRun = textRuns[i];
  69. if (currentLength + currentRun.TextSourceLength < length)
  70. {
  71. currentLength += currentRun.TextSourceLength;
  72. continue;
  73. }
  74. var firstCount = currentRun.TextSourceLength >= 1 ? i + 1 : i;
  75. var first = new List<DrawableTextRun>(firstCount);
  76. if (firstCount > 1)
  77. {
  78. for (var j = 0; j < i; j++)
  79. {
  80. first.Add(textRuns[j]);
  81. }
  82. }
  83. var secondCount = textRuns.Count - firstCount;
  84. if (currentLength + currentRun.TextSourceLength == length)
  85. {
  86. var second = secondCount > 0 ? new List<DrawableTextRun>(secondCount) : null;
  87. if (second != null)
  88. {
  89. var offset = currentRun.TextSourceLength >= 1 ? 1 : 0;
  90. for (var j = 0; j < secondCount; j++)
  91. {
  92. second.Add(textRuns[i + j + offset]);
  93. }
  94. }
  95. first.Add(currentRun);
  96. return new SplitResult<List<DrawableTextRun>>(first, second);
  97. }
  98. else
  99. {
  100. secondCount++;
  101. var second = new List<DrawableTextRun>(secondCount);
  102. if (currentRun is ShapedTextCharacters shapedTextCharacters)
  103. {
  104. var split = shapedTextCharacters.Split(length - currentLength);
  105. first.Add(split.First);
  106. second.Add(split.Second!);
  107. }
  108. for (var j = 1; j < secondCount; j++)
  109. {
  110. second.Add(textRuns[i + j]);
  111. }
  112. return new SplitResult<List<DrawableTextRun>>(first, second);
  113. }
  114. }
  115. return new SplitResult<List<DrawableTextRun>>(textRuns, null);
  116. }
  117. /// <summary>
  118. /// Shape specified text runs with specified paragraph embedding.
  119. /// </summary>
  120. /// <param name="textRuns">The text runs to shape.</param>
  121. /// <param name="paragraphProperties">The default paragraph properties.</param>
  122. /// <param name="resolvedFlowDirection">The resolved flow direction.</param>
  123. /// <returns>
  124. /// A list of shaped text characters.
  125. /// </returns>
  126. private static List<DrawableTextRun> ShapeTextRuns(List<TextRun> textRuns, TextParagraphProperties paragraphProperties,
  127. out FlowDirection resolvedFlowDirection)
  128. {
  129. var flowDirection = paragraphProperties.FlowDirection;
  130. var drawableTextRuns = new List<DrawableTextRun>();
  131. var biDiData = new BidiData((sbyte)flowDirection);
  132. foreach (var textRun in textRuns)
  133. {
  134. if (textRun.Text.IsEmpty)
  135. {
  136. var text = new char[textRun.TextSourceLength];
  137. biDiData.Append(text);
  138. }
  139. else
  140. {
  141. biDiData.Append(textRun.Text);
  142. }
  143. }
  144. var biDi = BidiAlgorithm.Instance.Value!;
  145. biDi.Process(biDiData);
  146. var resolvedEmbeddingLevel = biDi.ResolveEmbeddingLevel(biDiData.Classes);
  147. resolvedFlowDirection =
  148. (resolvedEmbeddingLevel & 1) == 0 ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;
  149. var processedRuns = new List<TextRun>(textRuns.Count);
  150. foreach (var coalescedRuns in CoalesceLevels(textRuns, biDi.ResolvedLevels))
  151. {
  152. processedRuns.AddRange(coalescedRuns);
  153. }
  154. for (var index = 0; index < processedRuns.Count; index++)
  155. {
  156. var currentRun = processedRuns[index];
  157. switch (currentRun)
  158. {
  159. case DrawableTextRun drawableRun:
  160. {
  161. drawableTextRuns.Add(drawableRun);
  162. break;
  163. }
  164. case ShapeableTextCharacters shapeableRun:
  165. {
  166. var groupedRuns = new List<ShapeableTextCharacters>(2) { shapeableRun };
  167. var text = currentRun.Text;
  168. var start = currentRun.Text.Start;
  169. var length = currentRun.Text.Length;
  170. var bufferOffset = currentRun.Text.BufferOffset;
  171. while (index + 1 < processedRuns.Count)
  172. {
  173. if (processedRuns[index + 1] is not ShapeableTextCharacters nextRun)
  174. {
  175. break;
  176. }
  177. if (shapeableRun.CanShapeTogether(nextRun))
  178. {
  179. groupedRuns.Add(nextRun);
  180. length += nextRun.Text.Length;
  181. if (start > nextRun.Text.Start)
  182. {
  183. start = nextRun.Text.Start;
  184. }
  185. if (bufferOffset > nextRun.Text.BufferOffset)
  186. {
  187. bufferOffset = nextRun.Text.BufferOffset;
  188. }
  189. text = new ReadOnlySlice<char>(text.Buffer, start, length, bufferOffset);
  190. index++;
  191. shapeableRun = nextRun;
  192. continue;
  193. }
  194. break;
  195. }
  196. var shaperOptions = new TextShaperOptions(currentRun.Properties!.Typeface.GlyphTypeface,
  197. currentRun.Properties.FontRenderingEmSize,
  198. shapeableRun.BidiLevel, currentRun.Properties.CultureInfo, paragraphProperties.DefaultIncrementalTab);
  199. drawableTextRuns.AddRange(ShapeTogether(groupedRuns, text, shaperOptions));
  200. break;
  201. }
  202. }
  203. }
  204. return drawableTextRuns;
  205. }
  206. private static IReadOnlyList<ShapedTextCharacters> ShapeTogether(
  207. IReadOnlyList<ShapeableTextCharacters> textRuns, ReadOnlySlice<char> text, TextShaperOptions options)
  208. {
  209. var shapedRuns = new List<ShapedTextCharacters>(textRuns.Count);
  210. var shapedBuffer = TextShaper.Current.ShapeText(text, options);
  211. for (var i = 0; i < textRuns.Count; i++)
  212. {
  213. var currentRun = textRuns[i];
  214. var splitResult = shapedBuffer.Split(currentRun.Text.Length);
  215. shapedRuns.Add(new ShapedTextCharacters(splitResult.First, currentRun.Properties));
  216. shapedBuffer = splitResult.Second!;
  217. }
  218. return shapedRuns;
  219. }
  220. /// <summary>
  221. /// Coalesces ranges of the same bidi level to form <see cref="ShapeableTextCharacters"/>
  222. /// </summary>
  223. /// <param name="textCharacters">The text characters to form <see cref="ShapeableTextCharacters"/> from.</param>
  224. /// <param name="levels">The bidi levels.</param>
  225. /// <returns></returns>
  226. private static IEnumerable<IReadOnlyList<TextRun>> CoalesceLevels(
  227. IReadOnlyList<TextRun> textCharacters,
  228. ReadOnlySlice<sbyte> levels)
  229. {
  230. if (levels.Length == 0)
  231. {
  232. yield break;
  233. }
  234. var levelIndex = 0;
  235. var runLevel = levels[0];
  236. TextRunProperties? previousProperties = null;
  237. TextCharacters? currentRun = null;
  238. var runText = ReadOnlySlice<char>.Empty;
  239. for (var i = 0; i < textCharacters.Count; i++)
  240. {
  241. var j = 0;
  242. currentRun = textCharacters[i] as TextCharacters;
  243. if (currentRun == null)
  244. {
  245. var drawableRun = textCharacters[i];
  246. yield return new[] { drawableRun };
  247. levelIndex += drawableRun.TextSourceLength;
  248. continue;
  249. }
  250. runText = currentRun.Text;
  251. for (; j < runText.Length;)
  252. {
  253. Codepoint.ReadAt(runText, j, out var count);
  254. if (levelIndex + 1 == levels.Length)
  255. {
  256. break;
  257. }
  258. levelIndex++;
  259. j += count;
  260. if (j == runText.Length)
  261. {
  262. yield return currentRun.GetShapeableCharacters(runText.Take(j), runLevel, ref previousProperties);
  263. runLevel = levels[levelIndex];
  264. continue;
  265. }
  266. if (levels[levelIndex] == runLevel)
  267. {
  268. continue;
  269. }
  270. // End of this run
  271. yield return currentRun.GetShapeableCharacters(runText.Take(j), runLevel, ref previousProperties);
  272. runText = runText.Skip(j);
  273. j = 0;
  274. // Move to next run
  275. runLevel = levels[levelIndex];
  276. }
  277. }
  278. if (currentRun is null || runText.IsEmpty)
  279. {
  280. yield break;
  281. }
  282. yield return currentRun.GetShapeableCharacters(runText, runLevel, ref previousProperties);
  283. }
  284. /// <summary>
  285. /// Fetches text runs.
  286. /// </summary>
  287. /// <param name="textSource">The text source.</param>
  288. /// <param name="firstTextSourceIndex">The first text source index.</param>
  289. /// <param name="endOfLine"></param>
  290. /// <param name="textSourceLength"></param>
  291. /// <returns>
  292. /// The formatted text runs.
  293. /// </returns>
  294. private static List<TextRun> FetchTextRuns(ITextSource textSource, int firstTextSourceIndex,
  295. out TextEndOfLine? endOfLine, out int textSourceLength)
  296. {
  297. textSourceLength = 0;
  298. endOfLine = null;
  299. var textRuns = new List<TextRun>();
  300. var textRunEnumerator = new TextRunEnumerator(textSource, firstTextSourceIndex);
  301. while (textRunEnumerator.MoveNext())
  302. {
  303. var textRun = textRunEnumerator.Current;
  304. if (textRun == null)
  305. {
  306. break;
  307. }
  308. if (textRun is TextEndOfLine textEndOfLine)
  309. {
  310. endOfLine = textEndOfLine;
  311. break;
  312. }
  313. switch (textRun)
  314. {
  315. case TextCharacters textCharacters:
  316. {
  317. if (TryGetLineBreak(textCharacters, out var runLineBreak))
  318. {
  319. var splitResult = new TextCharacters(textCharacters.Text.Take(runLineBreak.PositionWrap),
  320. textCharacters.Properties);
  321. textRuns.Add(splitResult);
  322. textSourceLength += runLineBreak.PositionWrap;
  323. return textRuns;
  324. }
  325. textRuns.Add(textCharacters);
  326. break;
  327. }
  328. default:
  329. {
  330. textRuns.Add(textRun);
  331. break;
  332. }
  333. }
  334. textSourceLength += textRun.TextSourceLength;
  335. }
  336. return textRuns;
  337. }
  338. private static bool TryGetLineBreak(TextRun textRun, out LineBreak lineBreak)
  339. {
  340. lineBreak = default;
  341. if (textRun.Text.IsEmpty)
  342. {
  343. return false;
  344. }
  345. var lineBreakEnumerator = new LineBreakEnumerator(textRun.Text);
  346. while (lineBreakEnumerator.MoveNext())
  347. {
  348. if (!lineBreakEnumerator.Current.Required)
  349. {
  350. continue;
  351. }
  352. lineBreak = lineBreakEnumerator.Current;
  353. return lineBreak.PositionWrap >= textRun.Text.Length || true;
  354. }
  355. return false;
  356. }
  357. private static bool TryMeasureLength(IReadOnlyList<DrawableTextRun> textRuns, double paragraphWidth, out int measuredLength)
  358. {
  359. measuredLength = 0;
  360. var currentWidth = 0.0;
  361. foreach (var currentRun in textRuns)
  362. {
  363. switch (currentRun)
  364. {
  365. case ShapedTextCharacters shapedTextCharacters:
  366. {
  367. var firstCluster = shapedTextCharacters.ShapedBuffer.GlyphClusters[0];
  368. var lastCluster = firstCluster;
  369. for (var i = 0; i < shapedTextCharacters.ShapedBuffer.Length; i++)
  370. {
  371. var glyphInfo = shapedTextCharacters.ShapedBuffer[i];
  372. if (currentWidth + glyphInfo.GlyphAdvance > paragraphWidth)
  373. {
  374. measuredLength += Math.Max(0, lastCluster - firstCluster);
  375. goto found;
  376. }
  377. lastCluster = glyphInfo.GlyphCluster;
  378. currentWidth += glyphInfo.GlyphAdvance;
  379. }
  380. measuredLength += currentRun.TextSourceLength;
  381. break;
  382. }
  383. case { } drawableTextRun:
  384. {
  385. if (currentWidth + drawableTextRun.Size.Width > paragraphWidth)
  386. {
  387. goto found;
  388. }
  389. measuredLength += currentRun.TextSourceLength;
  390. currentWidth += currentRun.Size.Width;
  391. break;
  392. }
  393. }
  394. }
  395. found:
  396. return measuredLength != 0;
  397. }
  398. /// <summary>
  399. /// Creates an empty text line.
  400. /// </summary>
  401. /// <returns>The empty text line.</returns>
  402. public static TextLineImpl CreateEmptyTextLine(int firstTextSourceIndex, double paragraphWidth, TextParagraphProperties paragraphProperties)
  403. {
  404. var flowDirection = paragraphProperties.FlowDirection;
  405. var properties = paragraphProperties.DefaultTextRunProperties;
  406. var glyphTypeface = properties.Typeface.GlyphTypeface;
  407. var text = new ReadOnlySlice<char>(s_empty, firstTextSourceIndex, 1);
  408. var glyph = glyphTypeface.GetGlyph(s_empty[0]);
  409. var glyphInfos = new[] { new GlyphInfo(glyph, firstTextSourceIndex) };
  410. var shapedBuffer = new ShapedBuffer(text, glyphInfos, glyphTypeface, properties.FontRenderingEmSize,
  411. (sbyte)flowDirection);
  412. var textRuns = new List<DrawableTextRun> { new ShapedTextCharacters(shapedBuffer, properties) };
  413. return new TextLineImpl(textRuns, firstTextSourceIndex, 0, paragraphWidth, paragraphProperties, flowDirection).FinalizeLine();
  414. }
  415. /// <summary>
  416. /// Performs text wrapping returns a list of text lines.
  417. /// </summary>
  418. /// <param name="textRuns"></param>
  419. /// <param name="firstTextSourceIndex">The first text source index.</param>
  420. /// <param name="paragraphWidth">The paragraph width.</param>
  421. /// <param name="paragraphProperties">The text paragraph properties.</param>
  422. /// <param name="resolvedFlowDirection"></param>
  423. /// <param name="currentLineBreak">The current line break if the line was explicitly broken.</param>
  424. /// <returns>The wrapped text line.</returns>
  425. private static TextLineImpl PerformTextWrapping(List<DrawableTextRun> textRuns, int firstTextSourceIndex,
  426. double paragraphWidth, TextParagraphProperties paragraphProperties, FlowDirection resolvedFlowDirection,
  427. TextLineBreak? currentLineBreak)
  428. {
  429. if(textRuns.Count == 0)
  430. {
  431. return CreateEmptyTextLine(firstTextSourceIndex,paragraphWidth, paragraphProperties);
  432. }
  433. if (!TryMeasureLength(textRuns, paragraphWidth, out var measuredLength))
  434. {
  435. measuredLength = 1;
  436. }
  437. var currentLength = 0;
  438. var lastWrapPosition = 0;
  439. var currentPosition = 0;
  440. for (var index = 0; index < textRuns.Count; index++)
  441. {
  442. var currentRun = textRuns[index];
  443. var lineBreaker = new LineBreakEnumerator(currentRun.Text);
  444. var breakFound = false;
  445. while (lineBreaker.MoveNext())
  446. {
  447. if (lineBreaker.Current.Required &&
  448. currentLength + lineBreaker.Current.PositionMeasure <= measuredLength)
  449. {
  450. //Explicit break found
  451. breakFound = true;
  452. currentPosition = currentLength + lineBreaker.Current.PositionWrap;
  453. break;
  454. }
  455. if (currentLength + lineBreaker.Current.PositionMeasure > measuredLength)
  456. {
  457. if (paragraphProperties.TextWrapping == TextWrapping.WrapWithOverflow)
  458. {
  459. if (lastWrapPosition > 0)
  460. {
  461. currentPosition = lastWrapPosition;
  462. breakFound = true;
  463. break;
  464. }
  465. //Find next possible wrap position (overflow)
  466. if (index < textRuns.Count - 1)
  467. {
  468. if (lineBreaker.Current.PositionWrap != currentRun.Text.Length)
  469. {
  470. //We already found the next possible wrap position.
  471. breakFound = true;
  472. currentPosition = currentLength + lineBreaker.Current.PositionWrap;
  473. break;
  474. }
  475. while (lineBreaker.MoveNext() && index < textRuns.Count)
  476. {
  477. currentPosition += lineBreaker.Current.PositionWrap;
  478. if (lineBreaker.Current.PositionWrap != currentRun.Text.Length)
  479. {
  480. break;
  481. }
  482. index++;
  483. if (index >= textRuns.Count)
  484. {
  485. break;
  486. }
  487. currentRun = textRuns[index];
  488. lineBreaker = new LineBreakEnumerator(currentRun.Text);
  489. }
  490. }
  491. else
  492. {
  493. currentPosition = currentLength + lineBreaker.Current.PositionWrap;
  494. }
  495. breakFound = true;
  496. break;
  497. }
  498. //We overflowed so we use the last available wrap position.
  499. currentPosition = lastWrapPosition == 0 ? measuredLength : lastWrapPosition;
  500. breakFound = true;
  501. break;
  502. }
  503. if (lineBreaker.Current.PositionMeasure != lineBreaker.Current.PositionWrap)
  504. {
  505. lastWrapPosition = currentLength + lineBreaker.Current.PositionWrap;
  506. }
  507. }
  508. if (!breakFound)
  509. {
  510. currentLength += currentRun.Text.Length;
  511. continue;
  512. }
  513. measuredLength = currentPosition;
  514. break;
  515. }
  516. var splitResult = SplitDrawableRuns(textRuns, measuredLength);
  517. var remainingCharacters = splitResult.Second;
  518. var lineBreak = remainingCharacters?.Count > 0 ?
  519. new TextLineBreak(currentLineBreak?.TextEndOfLine, resolvedFlowDirection, remainingCharacters) :
  520. null;
  521. if (lineBreak is null && currentLineBreak?.TextEndOfLine != null)
  522. {
  523. lineBreak = new TextLineBreak(currentLineBreak.TextEndOfLine, resolvedFlowDirection);
  524. }
  525. var textLine = new TextLineImpl(splitResult.First, firstTextSourceIndex, measuredLength,
  526. paragraphWidth, paragraphProperties, resolvedFlowDirection,
  527. lineBreak);
  528. return textLine.FinalizeLine();
  529. }
  530. private struct TextRunEnumerator
  531. {
  532. private readonly ITextSource _textSource;
  533. private int _pos;
  534. public TextRunEnumerator(ITextSource textSource, int firstTextSourceIndex)
  535. {
  536. _textSource = textSource;
  537. _pos = firstTextSourceIndex;
  538. Current = null;
  539. }
  540. // ReSharper disable once MemberHidesStaticFromOuterClass
  541. public TextRun? Current { get; private set; }
  542. public bool MoveNext()
  543. {
  544. Current = _textSource.GetTextRun(_pos);
  545. if (Current is null)
  546. {
  547. return false;
  548. }
  549. if (Current.TextSourceLength == 0)
  550. {
  551. return false;
  552. }
  553. _pos += Current.TextSourceLength;
  554. return true;
  555. }
  556. }
  557. /// <summary>
  558. /// Creates a shaped symbol.
  559. /// </summary>
  560. /// <param name="textRun">The symbol run to shape.</param>
  561. /// <param name="flowDirection">The flow direction.</param>
  562. /// <returns>
  563. /// The shaped symbol.
  564. /// </returns>
  565. internal static ShapedTextCharacters CreateSymbol(TextRun textRun, FlowDirection flowDirection)
  566. {
  567. var textShaper = TextShaper.Current;
  568. var glyphTypeface = textRun.Properties!.Typeface.GlyphTypeface;
  569. var fontRenderingEmSize = textRun.Properties.FontRenderingEmSize;
  570. var cultureInfo = textRun.Properties.CultureInfo;
  571. var shaperOptions = new TextShaperOptions(glyphTypeface, fontRenderingEmSize, (sbyte)flowDirection, cultureInfo);
  572. var shapedBuffer = textShaper.ShapeText(textRun.Text, shaperOptions);
  573. return new ShapedTextCharacters(shapedBuffer, textRun.Properties);
  574. }
  575. }
  576. }