示例#1
0
        public static sw.TextLayout GetTextLayout(Font font, string text)
        {
            var fontHandler = (FontHandler)font.Handler;
            var textLayout  = new sw.TextLayout(SDFactory.DirectWriteFactory, text, fontHandler.TextFormat, float.MaxValue, float.MaxValue);

            if (font.Strikethrough)
            {
                textLayout.SetStrikethrough(true, new sw.TextRange(0, text.Length));
            }
            if (font.Underline)
            {
                textLayout.SetUnderline(true, new sw.TextRange(0, text.Length));
            }
            return(textLayout);
        }
示例#2
0
        public DW.TextLayout GetTextLayout(Text.Font font, string text, float maxWidth)
        {
            var tl = new DW.TextLayout(
                _factory,
                text,
                GetTextFormat(font),
                maxWidth,
                9999999
                );

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (font.TextDecoration)
            {
            case TextDecoration.LineThrough:
                tl.SetStrikethrough(true, new DW.TextRange(0, text.Length));
                break;

            case TextDecoration.Underline:
                tl.SetUnderline(true, new DW.TextRange(0, text.Length));
                break;
            }

            return(tl);
        }
        /// <summary>
        /// Inits the font family names from DirectWrite
        /// </summary>
        private void InitTextFormatLayout()
        {
            FontFamilyName = "Gabriola";
            FontSize = 72;
            FontText = "Client Drawing Effect Example!";

            // Initialize a TextFormat
            CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, FontSize) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center };

            CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, ClientRectangle.Width, ClientRectangle.Height);

            RedDrawingeffect = new ColorDrawingEffect(Color.Red);
            BlueDrawingEffect = new ColorDrawingEffect(Color.Blue);
            GreenDrawingEffect = new ColorDrawingEffect(Color.Green);

            CurrentTextLayout.SetDrawingEffect(RedDrawingeffect, new TextRange(0, 14));
            CurrentTextLayout.SetDrawingEffect(BlueDrawingEffect, new TextRange(14, 7));
            CurrentTextLayout.SetDrawingEffect(GreenDrawingEffect, new TextRange(21, 8));
            CurrentTextLayout.SetUnderline(true, new TextRange(0, 20));
            CurrentTextLayout.SetStrikethrough(true, new TextRange(22, 7));

            // Set a stylistic typography
            using (var typo = new Typography(FactoryDWrite))
            {
                typo.AddFontFeature(new FontFeature(FontFeatureTag.StylisticSet7, 1));
                CurrentTextLayout.SetTypography(typo, CurrentTextRange);
            }
        }