diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 6f33b2b8..0920b778 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -442,8 +442,7 @@ namespace Volian.Print.Library // For example Header1 becomes H1 and Box2 becomes B2 return token.Substring(1, 1) + token.Substring(token.Length - 2, 1); } - private static Regex regexJustTokens = new Regex(@"^{([^{}\?]*}{)*[^{}\?]*}$"); - + private static Regex regexJustTokens = new Regex(@"^{([^{}]*}{)*[^{}]*}$"); private void AddPageListItems(Volian.Svg.Library.Svg mySvg, VEPROMS.CSLA.Library.PageStyle pageStyle, VEPROMS.CSLA.Library.SectionInfo section) { SvgGroup svgGroup = new SvgGroup(); @@ -492,7 +491,39 @@ namespace Volian.Print.Library svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayNumber)); break; default: - svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token)); + // see if it's a PSI token: + if (token.Contains(@"PS-")) + { + ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig; + if (procConfig != null) + { + int indx = token.IndexOf("-"); + string val = procConfig.GetValue("PSI", token.Substring(4,token.Length-5)); + svgGroup.Add(PageItemToSvgText(pageItem, val)); + } + } + else if (token.Contains(@"PS=")) + { + ProcedureConfig procConfig = section.MyProcedure.MyConfig as ProcedureConfig; + if (procConfig != null) + { + int indx = token.IndexOf("="); + int qindx = token.IndexOf("?", indx); + string pstok = token.Substring(indx + 1, qindx-indx-1); + string val = procConfig.GetValue("PSI", pstok); + int bindx = token.IndexOf("|", indx); + if (val == "Y") + val = token.Substring(qindx + 1, bindx - qindx - 1); + else + { + int eindx = token.IndexOf("}", bindx); + val = token.Substring(bindx + 1, eindx - bindx - 1); + } + if (val != null && val != "")svgGroup.Add(PageItemToSvgText(pageItem, val)); + } + } + else + svgGroup.Add(PageItemToSvgText(pageItem, pageItem.Token)); //_MyLog.InfoFormat("Token not processed {0}", token); break; } diff --git a/PROMS/Volian.Print.Library/vlnPrintObject.cs b/PROMS/Volian.Print.Library/vlnPrintObject.cs index 38f19c4b..ea896254 100644 --- a/PROMS/Volian.Print.Library/vlnPrintObject.cs +++ b/PROMS/Volian.Print.Library/vlnPrintObject.cs @@ -119,7 +119,7 @@ namespace Volian.Print.Library myColumnText.AddElement(iParagraph); //myColumnText.UseAscender = true;// Adjusts to the top of the text box. int status = myColumnText.Go(true); // Check to see if it will fit on the page. - if (ColumnText.HasMoreText(status) && throwException) + if (ColumnText.HasMoreText(status) && throwException) throw (new Exception("Paragraph longer than a page")); return 792F - myColumnText.YLine; // This gives the height of the Paragraph } @@ -245,7 +245,7 @@ namespace Volian.Print.Library } private static bool FontIsFixed(System.Drawing.Font font) { - iTextSharp.text.Font iFont = Rtf2iTextSharp.GetFont(font); + iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font); float fW = iFont.BaseFont.GetWidthPointKerned("W", 12); float fE = iFont.BaseFont.GetWidthPointKerned("!", 12); return fW == fE; diff --git a/PROMS/Volian.Svg.Library/iTextSharp.cs b/PROMS/Volian.Svg.Library/iTextSharp.cs index 5e8ca7e5..733f99fc 100644 --- a/PROMS/Volian.Svg.Library/iTextSharp.cs +++ b/PROMS/Volian.Svg.Library/iTextSharp.cs @@ -26,6 +26,37 @@ namespace Volian.Svg.Library pdfr.Close(); return retval; } + public static void RegisterFont(string fontName) + { + if (!iTextSharp.text.FontFactory.IsRegistered(fontName)) + { + foreach (string name in FontKey.GetValueNames()) + { + if (name.StartsWith(fontName)) + { + string fontFile = (string)FontKey.GetValue(name); + iTextSharp.text.FontFactory.Register(fontFile.Contains("\\") ? fontFile : FontFolder + "\\" + fontFile); + } + } + } + } + private static RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts"); + public static RegistryKey FontKey + { get { return _FontKey; } } + private static string _FontFolder = (String)Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("Shell Folders").GetValue("Fonts"); + public static string FontFolder + { get { return _FontFolder; } } + public static iTextSharp.text.Font GetFont(string fontName, int size, int style) + { + RegisterFont(fontName); + return iTextSharp.text.FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size / 2, style); + } + public static iTextSharp.text.Font GetFont(System.Drawing.Font font) // fontName, int size, int style) + { + RegisterFont(font.Name); + int style = (font.Bold ? iTextSharp.text.Font.BOLD : 0) + (font.Italic ? iTextSharp.text.Font.ITALIC : 0); + return iTextSharp.text.FontFactory.GetFont(font.Name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, font.Size, style); + } } internal static class SvgITextLibrary { @@ -494,8 +525,21 @@ namespace Volian.Svg.Library tmp.RestoreState(); } } + public partial class SvgText : SvgShapePart { + private static string ReplaceSpecialCharacter(Match m) + { + int i = int.Parse(m.ToString().Substring(2, m.ToString().Length - 3)); + char c = (char)i; + return c.ToString(); + } + private static string ReplaceHexCharacter(Match m) + { + int i = int.Parse(m.ToString().Substring(2, 2), System.Globalization.NumberStyles.HexNumber); + char c = (char)i; + return c.ToString(); + } public int Align { get @@ -525,11 +569,28 @@ namespace Volian.Svg.Library bool fill = FillColor != System.Drawing.Color.Transparent; bool stroke = OutlineWidth.Value != 0F && OutlineColor != System.Drawing.Color.Empty; int fontStyle = (Font.Bold ? iTextSharp.text.Font.BOLD : 0) + (Font.Italic ? iTextSharp.text.Font.ITALIC : 0); - iTextSharp.text.Font font = FontFactory.GetFont(Font.Name, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle); + VolianPdf.RegisterFont(Font.Name); + iTextSharp.text.Font font = FontFactory.GetFont(Font.Name, BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor)); + iTextSharp.text.pdf.FontSelector fs = new FontSelector(); + fs.AddFont(font); + if (font.BaseFont.GetWidthPoint("m", 12) == font.BaseFont.GetWidthPoint(".", 12)) + { + VolianPdf.RegisterFont("VESymbFix"); + fs.AddFont(FontFactory.GetFont("VESymbFix", BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor))); + } + else + { + VolianPdf.RegisterFont("Arial Unicode MS"); + fs.AddFont(FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor))); + } ColumnText ct = new ColumnText(cb); - Chunk chk = new Chunk(text, font); + text = Regex.Replace(text, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter)); + text = Regex.Replace(text, @"\\'[0-9a-fA-F][0-9a-fA-F]", new MatchEvaluator(ReplaceHexCharacter)); + Phrase ph = fs.Process(text); float x = scale.X(X); - float w = chk.GetWidthPoint(); + float w = 0; // chk.GetWidthPoint(); + foreach (Chunk chk in ph.Chunks) + w += chk.GetWidthPoint(); switch (Justify) { //case SvgJustify.Left: @@ -547,9 +608,9 @@ namespace Volian.Svg.Library float Offset = 0; if (Font.Underline) { - chk.SetUnderline(new Color(FillColor), 0, 0.047F, 0, -.1373F, PdfContentByte.LINE_CAP_ROUND); + foreach (Chunk chk in ph.Chunks) + chk.SetUnderline(new Color(FillColor), 0, 0.047F, 0, -.1373F, PdfContentByte.LINE_CAP_ROUND); } - Phrase ph = new Phrase(chk); ct.SetSimpleColumn(x, y + ph.Leading + Offset, xRight + 1F, y + ph.Leading + Offset - 2 * font.Size); ct.AddElement(ph); cb.SaveState();