/// <summary> /// Updates the cache that contains the result of laying out the label's text. /// </summary> /// <param name="availableSize">The size of the space that is available for laying out text.</param> private void UpdateTextLayoutResult(Size2D availableSize) { textLayoutCommands.Clear(); if (textParserResult.Count > 0 && Font.IsLoaded) { var unconstrainedWidth = Double.IsPositiveInfinity(availableSize.Width) && HorizontalAlignment != HorizontalAlignment.Stretch; var unconstrainedHeight = Double.IsPositiveInfinity(availableSize.Height) && VerticalAlignment != VerticalAlignment.Stretch; var constraintX = unconstrainedWidth ? null : (Int32?)Math.Ceiling(Display.DipsToPixels(availableSize.Width)); var constraintY = unconstrainedHeight ? null : (Int32?)Math.Ceiling(Display.DipsToPixels(availableSize.Height)); var cursorpos = textLayoutCommands.CursorPosition; var textRenderingMode = TextOptions.GetTextRenderingMode(this); var textScript = TextOptions.GetTextScript(this); var textLanguage = TextOptions.GetTextLanguage(this); var textDirection = FlowDirection == FlowDirection.RightToLeft ? TextDirection.RightToLeft : TextDirection.LeftToRight; var options = (textRenderingMode == TextRenderingMode.Shaped) ? TextLayoutOptions.Shape : TextLayoutOptions.None; var flags = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalContentAlignment, VerticalContentAlignment); var settings = new TextLayoutSettings(Font, constraintX, constraintY, flags, options, textDirection, textScript, FontStyle, null, textLanguage); View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings); View.Resources.TextRenderer.UpdateCursor(textLayoutCommands, cursorpos); } }
/// <summary> /// Updates the cache which contains the element's laid-out text. /// </summary> /// <param name="availableSize">The amount of space in which the element's text can be laid out.</param> private void UpdateTextLayoutCache(Size2D availableSize) { if (textLayoutCommands != null) { textLayoutCommands.Clear(); } if (View == null) { return; } var content = Content; var contentElement = content as UIElement; if (contentElement == null) { if (textLayoutCommands == null) { textLayoutCommands = new TextLayoutCommandStream(); } var font = GetValue <SourcedResource <UltravioletFont> >(TextElement.FontProperty); var fontStyle = GetValue <UltravioletFontStyle>(TextElement.FontStyleProperty); if (font.IsLoaded) { var availableSizeInPixels = Display.DipsToPixels(availableSize); var cursorpos = textLayoutCommands.CursorPosition; var textRenderingMode = TextOptions.GetTextRenderingMode(this); var textScript = TextOptions.GetTextScript(this); var textLanguage = TextOptions.GetTextLanguage(this); var textDirection = FlowDirection == FlowDirection.RightToLeft ? TextDirection.RightToLeft : TextDirection.LeftToRight; var options = (textRenderingMode == TextRenderingMode.Shaped) ? TextLayoutOptions.Shape : TextLayoutOptions.None; var flags = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalAlignment, VerticalAlignment); var settings = new TextLayoutSettings(font, (Int32)Math.Ceiling(availableSizeInPixels.Width), (Int32)Math.Ceiling(availableSizeInPixels.Height), flags, options, textDirection, textScript, fontStyle, null, textLanguage); View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings); View.Resources.TextRenderer.UpdateCursor(textLayoutCommands, cursorpos); } } }
/// <summary> /// Updates the cache that contains the result of laying out the label's text. /// </summary> /// <param name="availableSize">The size of the space that is available for laying out text.</param> private void UpdateTextLayoutResult(Size2D availableSize) { textLayoutCommands.Clear(); if (textParserResult.Count > 0 && Font.IsLoaded) { var unconstrainedWidth = Double.IsPositiveInfinity(availableSize.Width) && HorizontalAlignment != HorizontalAlignment.Stretch; var unconstrainedHeight = Double.IsPositiveInfinity(availableSize.Height) && VerticalAlignment != VerticalAlignment.Stretch; var constraintX = unconstrainedWidth ? null : (Int32?)Math.Ceiling(Display.DipsToPixels(availableSize.Width)); var constraintY = unconstrainedHeight ? null : (Int32?)Math.Ceiling(Display.DipsToPixels(availableSize.Height)); var flags = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalContentAlignment, VerticalContentAlignment); var settings = new TextLayoutSettings(Font, constraintX, constraintY, flags, FontStyle); View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings); } }
/// <summary> /// Updates the cache which contains the element's laid-out text. /// </summary> /// <param name="availableSize">The amount of space in which the element's text can be laid out.</param> private void UpdateTextLayoutCache(Size2D availableSize) { if (textLayoutCommands != null) { textLayoutCommands.Clear(); } if (View == null || containingControl == null) { return; } var content = Content; var contentElement = content as UIElement; if (contentElement == null) { if (textLayoutCommands == null) { textLayoutCommands = new TextLayoutCommandStream(); } var font = containingControl.Font; if (font.IsLoaded) { var availableSizeInPixels = Display.DipsToPixels(availableSize); var cursorpos = textLayoutCommands.CursorPosition; var flags = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalAlignment, VerticalAlignment); var settings = new TextLayoutSettings(font, (Int32)Math.Ceiling(availableSizeInPixels.Width), (Int32)Math.Ceiling(availableSizeInPixels.Height), flags, containingControl.FontStyle); View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings); View.Resources.TextRenderer.UpdateCursor(textLayoutCommands, cursorpos); } } }