This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user