Example #1
0
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            var factory = PerspexLocator.Current.GetService <DWrite.Factory>();

            using (var format = new DWrite.TextFormat(
                       factory,
                       fontFamily,
                       (DWrite.FontWeight)fontWeight,
                       (DWrite.FontStyle)fontStyle,
                       (float)fontSize))
            {
                TextLayout = new DWrite.TextLayout(
                    factory,
                    text ?? string.Empty,
                    format,
                    float.MaxValue,
                    float.MaxValue);
            }

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
Example #2
0
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight,
            TextWrapping wrapping)
        {
            var factory = AvaloniaLocator.Current.GetService <DWrite.Factory>();

            using (var format = new DWrite.TextFormat(
                       factory,
                       fontFamily,
                       (DWrite.FontWeight)fontWeight,
                       (DWrite.FontStyle)fontStyle,
                       (float)fontSize))
            {
                format.WordWrapping = wrapping == TextWrapping.Wrap ?
                                      DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    factory,
                    text ?? string.Empty,
                    format,
                    float.MaxValue,
                    float.MaxValue);
            }

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
Example #3
0
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight)
        {
            var factory = Locator.Current.GetService<DWrite.Factory>();

            var format = new DWrite.TextFormat(
                factory,
                fontFamily,
                (DWrite.FontWeight)fontWeight,
                (DWrite.FontStyle)fontStyle,
                (float)fontSize);

            TextLayout = new DWrite.TextLayout(
                factory,
                text ?? string.Empty,
                format,
                float.MaxValue,
                float.MaxValue);

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
        public FormattedTextImpl(
            string text,
            string fontFamily,
            double fontSize,
            FontStyle fontStyle,
            TextAlignment textAlignment,
            FontWeight fontWeight,
            TextWrapping wrapping)
        {
            var factory = AvaloniaLocator.Current.GetService<DWrite.Factory>();

            using (var format = new DWrite.TextFormat(
                factory,
                fontFamily,
                (DWrite.FontWeight)fontWeight,
                (DWrite.FontStyle)fontStyle,
                (float)fontSize))
            {
                format.WordWrapping = wrapping == TextWrapping.Wrap ? 
                    DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    factory,
                    text ?? string.Empty,
                    format,
                    float.MaxValue,
                    float.MaxValue);
            }

            TextLayout.TextAlignment = textAlignment.ToDirect2D();
        }
Example #5
0
        public FormattedTextImpl(
            string text,
            Typeface typeface,
            double fontSize,
            TextAlignment textAlignment,
            TextWrapping wrapping,
            Size constraint,
            IReadOnlyList <FormattedTextStyleSpan> spans)
        {
            Text = text;

            var font       = ((GlyphTypefaceImpl)typeface.GlyphTypeface.PlatformImpl).DWFont;
            var familyName = font.FontFamily.FamilyNames.GetString(0);

            using (var textFormat = new DWrite.TextFormat(
                       Direct2D1Platform.DirectWriteFactory,
                       familyName,
                       font.FontFamily.FontCollection,
                       (DWrite.FontWeight)typeface.Weight,
                       (DWrite.FontStyle)typeface.Style,
                       DWrite.FontStretch.Normal,
                       (float)fontSize))
            {
                textFormat.WordWrapping =
                    wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    Direct2D1Platform.DirectWriteFactory,
                    Text ?? string.Empty,
                    textFormat,
                    (float)constraint.Width,
                    (float)constraint.Height)
                {
                    TextAlignment = textAlignment.ToDirect2D()
                };
            }

            if (spans != null)
            {
                foreach (var span in spans)
                {
                    ApplySpan(span);
                }
            }

            Bounds = Measure();
        }
        public FormattedTextImpl(
            string text,
            Typeface typeface,
            TextAlignment textAlignment,
            TextWrapping wrapping,
            Size constraint,
            IReadOnlyList <FormattedTextStyleSpan> spans)
        {
            Text = text;
            var factory = AvaloniaLocator.Current.GetService <DWrite.Factory>();

            using (var format = new DWrite.TextFormat(
                       factory,
                       typeface?.FontFamilyName ?? "Courier New",
                       (DWrite.FontWeight)(typeface?.Weight ?? FontWeight.Normal),
                       (DWrite.FontStyle)(typeface?.Style ?? FontStyle.Normal),
                       (float)(typeface?.FontSize ?? 12)))
            {
                format.WordWrapping = wrapping == TextWrapping.Wrap ?
                                      DWrite.WordWrapping.Wrap :
                                      DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    factory,
                    text ?? string.Empty,
                    format,
                    (float)constraint.Width,
                    (float)constraint.Height)
                {
                    TextAlignment = textAlignment.ToDirect2D()
                };
            }

            if (spans != null)
            {
                foreach (var span in spans)
                {
                    ApplySpan(span);
                }
            }

            Size = Measure();
        }
Example #7
0
        public FormattedTextImpl(
            string text,
            Typeface typeface,
            TextAlignment textAlignment,
            TextWrapping wrapping,
            Size constraint,
            IReadOnlyList <FormattedTextStyleSpan> spans)
        {
            Text = text;

            var factory = AvaloniaLocator.Current.GetService <DWrite.Factory>();

            var textFormat = Direct2D1FontCollectionCache.GetTextFormat(typeface);

            textFormat.WordWrapping =
                wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

            TextLayout = new DWrite.TextLayout(
                factory,
                Text ?? string.Empty,
                textFormat,
                (float)constraint.Width,
                (float)constraint.Height)
            {
                TextAlignment = textAlignment.ToDirect2D()
            };

            textFormat.Dispose();

            if (spans != null)
            {
                foreach (var span in spans)
                {
                    ApplySpan(span);
                }
            }

            Size = Measure();
        }
Example #8
0
        public FormattedTextImpl(
            string text,
            Typeface typeface,
            TextAlignment textAlignment,
            TextWrapping wrapping,
            Size constraint,
            IReadOnlyList <FormattedTextStyleSpan> spans)
        {
            Text = text;

            using (var textFormat = Direct2D1FontCollectionCache.GetTextFormat(typeface))
            {
                textFormat.WordWrapping =
                    wrapping == TextWrapping.Wrap ? DWrite.WordWrapping.Wrap : DWrite.WordWrapping.NoWrap;

                TextLayout = new DWrite.TextLayout(
                    Direct2D1Platform.DirectWriteFactory,
                    Text ?? string.Empty,
                    textFormat,
                    (float)constraint.Width,
                    (float)constraint.Height)
                {
                    TextAlignment = textAlignment.ToDirect2D()
                };
            }

            if (spans != null)
            {
                foreach (var span in spans)
                {
                    ApplySpan(span);
                }
            }

            Bounds = Measure();
        }