protected void insertNames(string[][] names, string path) { string main = null; for (int k = 0; k < names.Length; ++k) { string[] name = names[k]; if (name[2].Equals("1033")) { main = name[3]; break; } } if (main == null) { main = names[0][3]; } BaseFontParameters p = new BaseFontParameters(path); mapper.Add(main, p); for (int k = 0; k < names.Length; ++k) { aliases.Add(names[k][3], main); } }
/** Looks for a BaseFont parameter associated with a name. * @param name the name * @return the BaseFont parameter or <CODE>null</CODE> if not found. */ public BaseFontParameters getBaseFontParameters(string name) { string alias = (string)aliases[name]; if (alias == null) { return((BaseFontParameters)mapper[name]); } BaseFontParameters p = (BaseFontParameters)mapper[alias]; if (p == null) { return((BaseFontParameters)mapper[name]); } else { return(p); } }
/** * Returns a BaseFont which can be used to represent the given NET Font * * @param font the font to be converted * @return a BaseFont which has similar properties to the provided Font */ public BaseFont netToPdf(System.Drawing.Font font) { try { BaseFontParameters p = getBaseFontParameters(font.Name); if (p != null) { return(BaseFont.createFont(p.fontName, p.encoding, p.embedded, p.cached, p.ttfAfm, p.pfb)); } string fontKey = null; string logicalName = font.Name; if (logicalName.Equals("DialogInput") || (logicalName.Equals("Monospaced"))) { if (font.Italic) { if (font.Bold) { fontKey = BaseFont.COURIER_BOLDOBLIQUE; } else { fontKey = BaseFont.COURIER_OBLIQUE; } } else { if (font.Bold) { fontKey = BaseFont.COURIER_BOLD; } else { fontKey = BaseFont.COURIER; } } } else if (logicalName.Equals("Serif")) { if (font.Italic) { if (font.Bold) { fontKey = BaseFont.TIMES_BOLDITALIC; } else { fontKey = BaseFont.TIMES_ITALIC; } } else { if (font.Bold) { fontKey = BaseFont.TIMES_BOLD; } else { fontKey = BaseFont.TIMES_ROMAN; } } } else // default, this catches Dialog and SansSerif { if (font.Italic) { if (font.Bold) { fontKey = BaseFont.HELVETICA_BOLDOBLIQUE; } else { fontKey = BaseFont.HELVETICA_OBLIQUE; } } else { if (font.Bold) { fontKey = BaseFont.HELVETICA_BOLD; } else { fontKey = BaseFont.HELVETICA; } } } return(BaseFont.createFont(fontKey, BaseFont.CP1252, false)); } catch (Exception e) { throw e; } }
/** Maps a name to a BaseFont parameter. * @param netName the name * @param parameters the BaseFont parameter */ public void putName(string netName, BaseFontParameters parameters) { mapper.Add(netName, parameters); }