Exemple #1
0
        public D2D_TextElements CreateNewTextElements(UText t)
        {
            var textLayout = new TextLayout(dwFact, t.text, new TextFormat(
                                                dwFact,
                                                t.font.name,
                                                t.font.bold ? FontWeight.Bold : FontWeight.Normal,
                                                t.font.italic ? FontStyle.Italic : FontStyle.Normal,
                                                TranslateFontSize(t.font.size))
            {
                ParagraphAlignment = Translate(t.valign),
                TextAlignment      = Translate(t.halign),
                WordWrapping       = t.wrapped ? WordWrapping.Wrap : WordWrapping.NoWrap
            }, t.width, t.height);

            // Set font ranges... textLayout just created, dont worry about any leftover ranges.
            foreach (var sr in t.SafeGetStyleRanges)
            {
                var tr = new TextRange(sr.start, sr.length);
                if (sr.fontOverride != null)
                {
                    UFont ft = (UFont)sr.fontOverride;
                    textLayout.SetFontFamilyName(ft.name, tr);
                    textLayout.SetFontSize(TranslateFontSize(ft.size), tr);
                    textLayout.SetFontStyle(ft.italic ? FontStyle.Italic : FontStyle.Normal, tr);
                    textLayout.SetFontWeight(ft.bold ? FontWeight.Bold : FontWeight.Normal, tr);
                }
                if (sr.fgOverride != null || sr.bgOverride != null)
                {
                    ClientTextEffect cte = new ClientTextEffect();
                    if (sr.fgOverride != null)
                    {
                        cte.fgBrush = CreateBrush(sr.fgOverride);
                    }
                    if (sr.bgOverride != null)
                    {
                        cte.bgBrush = CreateBrush(sr.bgOverride);
                    }
                    textLayout.SetDrawingEffect(cte, tr);
                }
            }

            // Set renderer with a default brush
            var def = new USolidBrush()
            {
                color = new Color(0)
            };
            var textRenderer = new D2D_ClientTextRenderer(realRenderer.renderTarget, new ClientTextEffect()
            {
                fgBrush = CreateBrush(def)
            });

            var ret = new D2D_TextElements(textLayout, textRenderer);

            realRenderer.renderTarget.Disposed += new EventHandler <EventArgs>((o, e) => t.Invalidate());
            return(ret);
        }
Exemple #2
0
 public D2D_TextElements(TextLayout textLayout, D2D_ClientTextRenderer textRenderer)
 {
     this.textLayout   = textLayout;
     this.textRenderer = textRenderer;
 }