public TextControlScreen(Window Parent) { InitializeComponent(); _parent = Parent; Margin = new Thickness(0); _parent = Parent; _cursorCanvas = new Canvas { Background = ZColorCheck.ZColorToBrush(1, ColorType.Foreground), Visibility = Visibility.Hidden }; cnvsTop.Children.Add(_cursorCanvas); _sound = new FrotzSound(); LayoutRoot.Children.Add(_sound); fColor = 1; bColor = 1; Background = ZColorCheck.ZColorToBrush(1, ColorType.Background); _substituion = new NumberSubstitution(); SetFontInfo(); Unloaded += (s, e) => { _regularLines?.Dispose(); _fixedWidthLines?.Dispose(); }; }
public AbsoluteScreen(Window Parent) { InitializeComponent(); _parent = Parent; _scrollback = new ScrollbackArea(this); _cursorCanvas = new System.Windows.Controls.Canvas(); _cursorCanvas.Background = ZColorCheck.ZColorToBrush(1, ColorType.Foreground); _cursorCanvas.Visibility = System.Windows.Visibility.Visible; cnvsTop.Children.Add(_cursorCanvas); _sound = new FrotzSound(); LayoutRoot.Children.Add(_sound); _substituion = new NumberSubstitution(); setFontInfo(); _currentInfo = new CharDisplayInfo(1, 0, 1, 1); bColor = 1; this.Background = ZColorCheck.ZColorToBrush(bColor, ColorType.Background); this.MouseDown += new MouseButtonEventHandler(AbsoluteScreen_MouseDown); this.MouseDoubleClick += new MouseButtonEventHandler(AbsoluteScreen_MouseDoubleClick); }
public TextAnalysis(String Text, String localName, ReadingDirection readingDirection, NumberSubstitution numberSubstitution) { text_ = Text; localeName_ = localName; readingDirection_ = readingDirection; numberSubstitution_ = numberSubstitution; }
/// <summary> /// Creates a new VisualLineElementTextRunProperties instance that copies its values /// from the specified <paramref name="textRunProperties"/>. /// For the <see cref="TextDecorations"/> and <see cref="TextEffects"/> collections, deep copies /// are created if those collections are not frozen. /// </summary> public VisualLineElementTextRunProperties(TextRunProperties textRunProperties) { if (textRunProperties == null) { throw new ArgumentNullException("textRunProperties"); } backgroundBrush = textRunProperties.BackgroundBrush; baselineAlignment = textRunProperties.BaselineAlignment; cultureInfo = textRunProperties.CultureInfo; fontHintingEmSize = textRunProperties.FontHintingEmSize; fontRenderingEmSize = textRunProperties.FontRenderingEmSize; foregroundBrush = textRunProperties.ForegroundBrush; typeface = textRunProperties.Typeface; textDecorations = textRunProperties.TextDecorations; if (textDecorations != null && !textDecorations.IsFrozen) { textDecorations = textDecorations.Clone(); } textEffects = textRunProperties.TextEffects; if (textEffects != null && !textEffects.IsFrozen) { textEffects = textEffects.Clone(); } typographyProperties = textRunProperties.TypographyProperties; numberSubstitution = textRunProperties.NumberSubstitution; }
private static CultureInfo GetNumberCulture(TextRunProperties properties, out NumberSubstitutionMethod method, out bool ignoreUserOverride) { ignoreUserOverride = true; NumberSubstitution sub = properties.NumberSubstitution; if (sub == null) { method = NumberSubstitutionMethod.AsCulture; return(CultureMapper.GetSpecificCulture(properties.CultureInfo)); } method = sub.Substitution; switch (sub.CultureSource) { case NumberCultureSource.Text: return(CultureMapper.GetSpecificCulture(properties.CultureInfo)); case NumberCultureSource.User: ignoreUserOverride = false; return(CultureInfo.CurrentCulture); case NumberCultureSource.Override: return(sub.CultureOverride); } return(null); }
/// <summary> /// Determines whether or not the text in <paramref name="textBlock"/> is currently being trimmed due to width or height constraints. /// </summary> /// <param name="textBlock">The <see cref="TextBlock"/> to evaluate.</param> /// <returns><c>true</c> if the text is currently being trimmed; otherwise <c>false</c></returns> private static bool EvaluateIsTextTrimmed([NotNull] TextBlock textBlock) { var fontFamily = textBlock.FontFamily; var text = textBlock.Text; if ((fontFamily == null) || (text == null)) { return(false); } var typeface = new Typeface(fontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch); var numberSubstitution = new NumberSubstitution(NumberSubstitution.GetCultureSource(textBlock), NumberSubstitution.GetCultureOverride(textBlock), NumberSubstitution.GetSubstitution(textBlock)); #if NET45 var formattedText = new FormattedText(text, CultureInfo.CurrentCulture, textBlock.FlowDirection, typeface, textBlock.FontSize, textBlock.Foreground, numberSubstitution, TextOptions.GetTextFormattingMode(textBlock)); #else var pixelsPerDip = textBlock.GetPhysicalPixelSize().Height; var formattedText = new FormattedText(text, CultureInfo.CurrentCulture, textBlock.FlowDirection, typeface, textBlock.FontSize, textBlock.Foreground, numberSubstitution, TextOptions.GetTextFormattingMode(textBlock), pixelsPerDip); #endif var padding = textBlock.Padding; var actualWidth = textBlock.ActualWidth - padding.Left - padding.Right; var actualHeight = textBlock.ActualHeight - padding.Top - padding.Bottom; if (textBlock.TextWrapping != TextWrapping.NoWrap) { formattedText.MaxTextWidth = actualWidth; } var isTextTrimmed = ((Math.Floor(formattedText.Height) - actualHeight) > 0.0001) || (Math.Floor(formattedText.Width) - actualWidth > 0.0001); return(isTextTrimmed); }
public TextControlScreen(Window Parent) { InitializeComponent(); _parent = Parent; this.Margin = new Thickness(0); _parent = Parent; _cursorCanvas = new System.Windows.Controls.Canvas(); _cursorCanvas.Background = ZColorCheck.ZColorToBrush(1, ColorType.Foreground); _cursorCanvas.Visibility = System.Windows.Visibility.Hidden; cnvsTop.Children.Add(_cursorCanvas); _sound = new FrotzSound(); LayoutRoot.Children.Add(_sound); fColor = 1; bColor = 1; this.Background = ZColorCheck.ZColorToBrush(1, ColorType.Background); _substituion = new NumberSubstitution(); setFontInfo(); }
/// <summary> /// Creates a new System.Windows.Media.FormattedText of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <param name="emSize">The font size in em.</param> /// <param name="flowDirection">The flow direction of the font</param> /// <param name="textFormattingMode">The text formatting mode of the font</param> /// <param name="numberSubstitution">The number substitution of the font.</param> /// <returns>A new System.Windows.Media.FormattedText</returns> public static FormattedText CreateFormattedText(this EFontAwesomeIcon icon, Brush foregroundBrush, double emSize, FlowDirection flowDirection, TextFormattingMode textFormattingMode, NumberSubstitution numberSubstitution) { return(new FormattedText(icon.GetUnicode(), CultureInfo.InvariantCulture, flowDirection, icon.GetTypeFace(), emSize, foregroundBrush, numberSubstitution, textFormattingMode)); }
/// <summary> /// 测量字符串长度 /// </summary> /// <param name="text">要测量的文本</param> /// <param name="cultureInfo">区域信息</param> /// <param name="typeface">字符样式组合</param> /// <param name="flowDirection">测量方向</param> /// <param name="fontSize">字体大小</param> /// <param name="foreground">字体Brush</param> /// <param name="numberSubstitution">要应用于文本的数字替换行为</param> /// <param name="textFormattingMode">要应用于文本的 System.Windows.Media.TextFormattingMode</param> /// <returns>符串长度</returns> public static Size MeasureTextSize(string text, CultureInfo cultureInfo, Typeface typeface, FlowDirection flowDirection, double fontSize, Brush foreground, NumberSubstitution numberSubstitution, TextFormattingMode textFormattingMode) { var formattedText = new FormattedText(text, cultureInfo, flowDirection, typeface, fontSize, foreground, numberSubstitution, textFormattingMode); return(GetTextSize(formattedText)); }
private static Geometry BuildGeometry(string charachters, Typeface typeface, NumberSubstitution numberSubstitution) { var result = new FormattedText(charachters, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 24, Brushes.Black, numberSubstitution, TextFormattingMode.Display, 90) .BuildGeometry(new Point(9, 9)); result.Freeze(); return(result); }
/// <summary> /// 测量字符串长度 /// </summary> /// <param name="visual">目标的界面控件</param> /// <param name="text">要测量的文本</param> /// <param name="cultureInfo">区域信息</param> /// <param name="typeface">字符样式组合</param> /// <param name="flowDirection">测量方向</param> /// <param name="fontSize">字体大小</param> /// <param name="foreground">字体Brush</param> /// <param name="numberSubstitution">要应用于文本的数字替换行为</param> /// <param name="textFormattingMode">要应用于文本的 System.Windows.Media.TextFormattingMode</param> /// <returns>符串长度</returns> public static Size MeasureTextSize(Visual visual, string text, CultureInfo cultureInfo, Typeface typeface, FlowDirection flowDirection, double fontSize, Brush foreground, NumberSubstitution numberSubstitution, TextFormattingMode textFormattingMode) { var pixelsPerDip = VisualTreeHelper.GetDpi(visual).PixelsPerDip; var formattedText = new FormattedText(text, cultureInfo, flowDirection, typeface, fontSize, foreground, numberSubstitution, textFormattingMode, pixelsPerDip); return(GetTextSize(formattedText)); }
// ------------------------------------------------------------------ // Retrieve Number substitution properties from given element // ------------------------------------------------------------------ internal static NumberSubstitution GetNumberSubstitution(DependencyObject element) { NumberSubstitution numberSubstitution = new NumberSubstitution(); numberSubstitution.CultureSource = (NumberCultureSource)element.GetValue(NumberSubstitution.CultureSourceProperty); numberSubstitution.CultureOverride = (CultureInfo)element.GetValue(NumberSubstitution.CultureOverrideProperty); numberSubstitution.Substitution = (NumberSubstitutionMethod)element.GetValue(NumberSubstitution.SubstitutionProperty); return(numberSubstitution); }
public GeometryRenderViewModel(IScarletCommandBuilder commandBuilder) : base(commandBuilder) { _typeface = new Typeface("Tahoma"); _numberSubstitution = new NumberSubstitution(); _geomtries = Enumerable.Range(0, 5000) .Select(c => (c % (97 - 32)) + 32) .Select(c => (char)c) .Select(c => new GeometryContainer(BuildGeometry(new string(c, 1), _typeface, _numberSubstitution))) .ToArray(); }
static bool Equals(NumberSubstitution a, NumberSubstitution b) { if (a == b) { return(true); } if (a == null || b == null) { return(false); } return(a.Equals(b)); }
internal double DetermineWidth(String Text) { NumberSubstitution ns = new NumberSubstitution(); FormattedText ft = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch), this.FontSize, this.Foreground, ns, TextFormattingMode.Display); return(ft.Width); }
public void SetNumberSubstitution(int textPosition, int textLength, NumberSubstitution numberSubstitution) { SetCurrentRun(textPosition); SplitCurrentRun(textPosition); while (textLength > 0) { int nextRunIndex = FetchNextRunIndex(ref textLength); LinkedRun run = runs_[nextRunIndex]; run.isNumberSubstituted = (numberSubstitution != null); runs_[nextRunIndex] = run; } }
public FormattedTextBuilder([NotNull] IFontInfo fontInfo, string text) { mFontInfo = fontInfo ?? throw new ArgumentNullException(nameof(fontInfo)); mText = text ?? string.Empty; mCulture = CultureInfo.CurrentCulture; mFlowDirection = System.Windows.FlowDirection.LeftToRight; mForeground = Brushes.Black; mNumberSubstitution = null; mTextFormattingMode = System.Windows.Media.TextFormattingMode.Display; mDpi = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null, null) as double? ?? 96.0; }
private void SetLayoutNumbers(LayoutNumbers layoutNumbers) { // Creates a number substitution to select which digits are displayed. String localName = "en-us"; if (layoutNumbers == LayoutNumbers.Arabic) { localName = "ar-eg"; } NumberSubstitution numberSubstitution = new NumberSubstitution(FactoryDWrite, NumberSubstitutionMethod.Contextual, localName, true); flowLayout.SetNumberSubstitution(numberSubstitution); SetLayoutText(textMode_); numberSubstitution.Dispose(); }
/// <summary> /// Constructing TextRunProperties /// </summary> /// <param name="typeface">typeface</param> /// <param name="size">text size</param> /// <param name="hintingSize">text size for Truetype hinting program</param> /// <param name="culture">text culture info</param> /// <param name="textDecorations">TextDecorations </param> /// <param name="foregroundBrush">text foreground brush</param> /// <param name="backgroundBrush">highlight background brush</param> /// <param name="baselineAlignment">text vertical alignment to its container</param> /// <param name="substitution">number substitution behavior to apply to the text; can be null, /// in which case the default number substitution method for the text culture is used</param> public GenericTextRunProperties( Typeface typeface, double size, double hintingSize, TextDecorationCollection textDecorations, Brush foregroundBrush, Brush backgroundBrush, BaselineAlignment baselineAlignment, CultureInfo culture, NumberSubstitution substitution ) { _typeface = typeface; _emSize = size; _emHintingSize = hintingSize; _textDecorations = textDecorations; _foregroundBrush = foregroundBrush; _backgroundBrush = backgroundBrush; _baselineAlignment = baselineAlignment; _culture = culture; _numberSubstitution = substitution; }
protected override void OnSetNumberSubstitution(uint textPosition, uint textLength, NumberSubstitution numberSubstitution) { base.OnSetNumberSubstitution(textPosition, textLength, numberSubstitution); }
public void SetNumberSubstitution(NumberSubstitution numberSubstitution) { numberSubstitution_ = numberSubstitution; }
/// <summary> /// Sets the <see cref="NumberSubstitution"/>. /// </summary> public void SetNumberSubstitution(NumberSubstitution value) { numberSubstitution = value; }
public TermText(string textToFormat, CultureInfo culture, FlowDirection flowDirection, Typeface typeface, double emSize, Brush foreground, NumberSubstitution numberSubstitution, TextFormattingMode textFormattingMode) : base(textToFormat, culture, flowDirection, typeface, emSize, foreground, numberSubstitution, textFormattingMode) { }
public IFormattedTextBuilder NumberSubstitution(NumberSubstitution numberSubstitution) { mNumberSubstitution = numberSubstitution; return(this); }