private void DrawText(Vex.Text tx, DDW.Vex.Matrix m) { for (int i = 0; i < tx.TextRuns.Count; i++) { Vex.TextRun tr = tx.TextRuns[i]; string s = tr.Text; FontStyle style = tr.isBold ? FontStyle.Bold : FontStyle.Regular; if (tr.isItalic) { style |= FontStyle.Italic; } Font font = new Font(tr.FontName, tr.FontSize, style, GraphicsUnit.Pixel); System.Drawing.Color col = System.Drawing.Color.FromArgb(tr.Color.A, tr.Color.R, tr.Color.G, tr.Color.B); Brush b = new SolidBrush(col); g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawString(s, font, b, tx.Matrix.TranslateX + m.TranslateX + tr.Left, tx.Matrix.TranslateY + m.TranslateY + tr.Top); b.Dispose(); } }
public TextRun2D(TextRun tr) { this.Text = tr.Text; this.FontName = tr.FontName; this.FontSize = tr.FontSize; this.Top = tr.Top; this.Left = tr.Left; this.Color = tr.Color; this.isHtml = tr.isHtml; this.isBold = tr.isBold; this.isItalic = tr.isItalic; this.isMultiline = tr.isMultiline; this.isUnderlined = tr.isUnderlined; this.isStrikeout = tr.isStrikeout; this.isWrapped = tr.isWrapped; this.isPassword = tr.isPassword; this.isEditable = tr.isEditable; this.isSelectable = tr.isSelectable; }
protected void WriteTextAttributes(TextRun tr) { xw.WriteStartAttribute("FontSize"); xw.WriteValue(tr.FontSize); xw.WriteEndAttribute(); // decide weather to use ttf resource or not if (BuiltInFonts.Contains(tr.FontName)) { xw.WriteStartAttribute("FontFamily"); xw.WriteValue(tr.FontName); xw.WriteEndAttribute(); } else { if (FontUtil.GetInstance().FontMap.ContainsKey(tr.FontName)) { // FontFamily="Resources/#Calligrapher" xw.WriteStartAttribute("FontFamily"); xw.WriteValue(v.ResourceFolder + @"/#" + tr.FontName); xw.WriteEndAttribute(); Utils.CopyFontToResources(tr.FontName, v.ResourceFolder); } else { xw.WriteStartAttribute("FontFamily"); xw.WriteValue(tr.FontName); xw.WriteEndAttribute(); } } xw.WriteStartAttribute("Foreground"); xw.WriteColor(tr.Color); xw.WriteEndAttribute(); if (tr.isItalic) { xw.WriteStartAttribute("FontStyle"); xw.WriteValue("Italic"); xw.WriteEndAttribute(); } if (tr.isBold) { xw.WriteStartAttribute("FontWeight"); xw.WriteValue("Bold"); xw.WriteEndAttribute(); } }
public void GetTextFromRecords(List<TextRecord> records, List<TextRun> runs) { float fontSize = 12F; // default string fontName = "Arial"; // default Color fontColor = new Color(0,0,0); // default black uint fontId; uint[] codeTable = null; bool isBold = false; bool isItalic = false; int yOffset = 0; TextRun prevRun = null; float vpad = 0; for (int i = 0; i < records.Count; i++) { TextRecord r = records[i]; TextRun run = new TextRun(); runs.Add(run); string text = ""; if (r.YOffset > yOffset) { yOffset = r.YOffset; if (prevRun != null) { prevRun.isMultiline = true; } else if(r.TextHeight != 0) { // the space between the lines of the font vpad = (r.TextHeight - r.YOffset)/twips; } } if (r.StyleFlagsHasFont) { fontSize = r.TextHeight / twips; fontId = r.FontID; if (swf.Fonts.ContainsKey(fontId)) { DefineFont2_3 f = swf.Fonts[fontId]; fontName = f.FontName; codeTable = f.CodeTable; isBold = f.FontFlagsBold; isItalic = f.FontFlagsItalic; } } if (r.StyleFlagsHasColor) { fontColor = ParseRGBA(r.TextColor); } if (codeTable != null) { for (int j = 0; j < r.GlyphEntries.Length; j++) { GlyphEntry ge = r.GlyphEntries[j]; uint charCode = codeTable[ge.GlyphIndex]; text += (char)charCode; } } run.FontName = fontName; run.FontSize = fontSize; run.Color = fontColor; run.Text = text; run.isContinuous = !(r.StyleFlagsHasYOffset || r.StyleFlagsHasXOffset); run.isBold = isBold; run.isItalic = isItalic; //if () //{ // run.Top = (r.YOffset - r.TextHeight) / twips; //} run.Top = (yOffset / twips) - fontSize + vpad; if (r.StyleFlagsHasXOffset) { run.Left = r.XOffset / twips; } prevRun = run; } }
private void ConvertStringToTextRuns(DefineEditTextTag tag, List<TextRun> runs) { string s = (tag.InitialText == null) ? "" : tag.InitialText; string[] sts = s.Split('\r'); // seems to be the only gen'd linebreak string fontName = ""; if (swf.Fonts.ContainsKey(tag.FontID)) { fontName = swf.Fonts[tag.FontID].FontName; } Color c = ParseRGBA(tag.TextColor); bool isMultiline = sts.Length > 1; for (int i = 0; i < sts.Length; i++) { TextRun tr = new TextRun(); tr.isEditable = true; tr.isSelectable = true; tr.Color = c; tr.isMultiline = isMultiline; if(tag.HasFont) { tr.FontName = fontName; } tr.FontSize = tag.FontHeight / 20; tr.Text = sts[i]; runs.Add(tr); } }