internal virtual void ResolveFont(SvgDrawContext context) { FontProvider provider = context.GetFontProvider(); FontSet tempFonts = context.GetTempFonts(); font = null; if (!provider.GetFontSet().IsEmpty() || (tempFonts != null && !tempFonts.IsEmpty())) { String fontFamily = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_FAMILY); String fontWeight = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_WEIGHT); String fontStyle = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_STYLE); fontFamily = fontFamily != null?fontFamily.Trim() : ""; FontInfo fontInfo = ResolveFontName(fontFamily, fontWeight, fontStyle, provider, tempFonts); font = provider.GetPdfFont(fontInfo, tempFonts); } if (font == null) { try { // TODO: DEVSIX-2057 each call of createFont() create a new instance of PdfFont. // FontProvider shall be used instead. font = PdfFontFactory.CreateFont(); } catch (System.IO.IOException e) { throw new SvgProcessingException(SvgLogMessageConstant.FONT_NOT_FOUND, e); } } }
protected internal override void DoDraw(SvgDrawContext context) { if (this.attributesAndStyles != null && this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.TEXT_CONTENT )) { PdfCanvas currentCanvas = context.GetCurrentCanvas(); String xRawValue = this.attributesAndStyles.Get(SvgConstants.Attributes.X); String yRawValue = this.attributesAndStyles.Get(SvgConstants.Attributes.Y); String fontSizeRawValue = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_SIZE); IList <String> xValuesList = SvgCssUtils.SplitValueList(xRawValue); IList <String> yValuesList = SvgCssUtils.SplitValueList(yRawValue); float x = 0f; float y = 0f; float fontSize = 0f; if (fontSizeRawValue != null && !String.IsNullOrEmpty(fontSizeRawValue)) { fontSize = CssUtils.ParseAbsoluteLength(fontSizeRawValue, CommonCssConstants.PT); } if (!xValuesList.IsEmpty()) { x = CssUtils.ParseAbsoluteLength(xValuesList[0]); } if (!yValuesList.IsEmpty()) { y = CssUtils.ParseAbsoluteLength(yValuesList[0]); } currentCanvas.BeginText(); FontProvider provider = context.GetFontProvider(); FontSet tempFonts = context.GetTempFonts(); PdfFont font = null; if (!provider.GetFontSet().IsEmpty() || (tempFonts != null && !tempFonts.IsEmpty())) { String fontFamily = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_FAMILY); String fontWeight = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_WEIGHT); String fontStyle = this.attributesAndStyles.Get(SvgConstants.Attributes.FONT_STYLE); fontFamily = fontFamily != null?fontFamily.Trim() : ""; FontInfo fontInfo = ResolveFontName(fontFamily, fontWeight, fontStyle, provider, tempFonts); font = provider.GetPdfFont(fontInfo, tempFonts); } if (font == null) { try { // TODO (DEVSIX-2057) // TODO each call of createFont() create a new instance of PdfFont. // TODO FontProvider shall be used instead. font = PdfFontFactory.CreateFont(); } catch (System.IO.IOException e) { throw new SvgProcessingException(SvgLogMessageConstant.FONT_NOT_FOUND, e); } } currentCanvas.SetFontAndSize(font, fontSize); //Current transformation matrix results in the character glyphs being mirrored, correct with inverse tf currentCanvas.SetTextMatrix(1, 0, 0, -1, x, y); currentCanvas.SetColor(ColorConstants.BLACK, true); currentCanvas.ShowText(this.attributesAndStyles.Get(SvgConstants.Attributes.TEXT_CONTENT)); currentCanvas.EndText(); } }