internal PdfType0Font(TrueTypeFont ttf, String cmap) : base() { if (!cmap.Equals(PdfEncodings.IDENTITY_H) && !cmap.Equals(PdfEncodings.IDENTITY_V)) { throw new PdfException("only.identity.cmaps.supports.with.truetype"); } if (!ttf.GetFontNames().AllowEmbedding()) { throw new PdfException("1.cannot.be.embedded.due.to.licensing.restrictions").SetMessageParams(ttf.GetFontNames ().GetFontName() + ttf.GetFontNames().GetStyle()); } this.fontProgram = ttf; this.embedded = true; vertical = cmap.EndsWith("V"); cmapEncoding = new CMapEncoding(cmap); longTag = new LinkedDictionary <int, int[]>(); cidFontType = CID_FONT_TYPE_2; if (ttf.IsFontSpecific()) { specificUnicodeDifferences = new char[256]; byte[] bytes = new byte[1]; for (int k = 0; k < 256; ++k) { bytes[0] = (byte)k; String s = PdfEncodings.ConvertToString(bytes, null); char ch = s.Length > 0 ? s[0] : '?'; specificUnicodeDifferences[k] = ch; } } }
internal PdfType0Font(TrueTypeFont ttf, String cmap) : base() { if (!PdfEncodings.IDENTITY_H.Equals(cmap) && !PdfEncodings.IDENTITY_V.Equals(cmap)) { throw new PdfException(PdfException.OnlyIdentityCMapsSupportsWithTrueType); } if (!ttf.GetFontNames().AllowEmbedding()) { throw new PdfException(PdfException.CannotBeEmbeddedDueToLicensingRestrictions).SetMessageParams(ttf.GetFontNames ().GetFontName() + ttf.GetFontNames().GetStyle()); } this.fontProgram = ttf; this.embedded = true; vertical = cmap.EndsWith("V"); cmapEncoding = new CMapEncoding(cmap); longTag = new SortedSet <int>(); cidFontType = CID_FONT_TYPE_2; if (ttf.IsFontSpecific()) { specificUnicodeDifferences = new char[256]; byte[] bytes = new byte[1]; for (int k = 0; k < 256; ++k) { bytes[0] = (byte)k; String s = PdfEncodings.ConvertToString(bytes, null); char ch = s.Length > 0 ? s[0] : '?'; specificUnicodeDifferences[k] = ch; } } }
public override GlyphLine CreateGlyphLine(String content) { IList <Glyph> glyphs = new List <Glyph>(); if (cidFontType == CID_FONT_TYPE_0) { int len = content.Length; if (cmapEncoding.IsDirect()) { for (int k = 0; k < len; ++k) { Glyph glyph = fontProgram.GetGlyphByCode((int)content[k]); if (glyph != null) { glyphs.Add(glyph); } } } else { for (int k = 0; k < len; ++k) { int ch; if (TextUtil.IsSurrogatePair(content, k)) { ch = TextUtil.ConvertToUtf32(content, k); k++; } else { ch = content[k]; } glyphs.Add(GetGlyph(ch)); } } } else { if (cidFontType == CID_FONT_TYPE_2) { TrueTypeFont ttf = (TrueTypeFont)fontProgram; int len = content.Length; if (ttf.IsFontSpecific()) { byte[] b = PdfEncodings.ConvertToBytes(content, "symboltt"); len = b.Length; for (int k = 0; k < len; ++k) { Glyph glyph = fontProgram.GetGlyph(b[k] & 0xff); if (glyph != null) { glyphs.Add(glyph); } } } else { for (int k = 0; k < len; ++k) { int val; if (TextUtil.IsSurrogatePair(content, k)) { val = TextUtil.ConvertToUtf32(content, k); k++; } else { val = content[k]; } glyphs.Add(GetGlyph(val)); } } } else { throw new PdfException("font.has.no.suitable.cmap"); } } return(new GlyphLine(glyphs)); }
public override int AppendAnyGlyph(String text, int from, IList <Glyph> glyphs) { int process = 1; if (cidFontType == CID_FONT_TYPE_0) { if (cmapEncoding.IsDirect()) { Glyph glyph = fontProgram.GetGlyphByCode((int)text[from]); if (glyph != null) { glyphs.Add(glyph); } } else { int ch; if (iText.IO.Util.TextUtil.IsSurrogatePair(text, from)) { ch = iText.IO.Util.TextUtil.ConvertToUtf32(text, from); process = 2; } else { ch = text[from]; } glyphs.Add(GetGlyph(ch)); } } else { if (cidFontType == CID_FONT_TYPE_2) { TrueTypeFont ttf = (TrueTypeFont)fontProgram; if (ttf.IsFontSpecific()) { byte[] b = PdfEncodings.ConvertToBytes(text, "symboltt"); if (b.Length > 0) { Glyph glyph = fontProgram.GetGlyph(b[0] & 0xff); if (glyph != null) { glyphs.Add(glyph); } } } else { int ch; if (iText.IO.Util.TextUtil.IsSurrogatePair(text, from)) { ch = iText.IO.Util.TextUtil.ConvertToUtf32(text, from); process = 2; } else { ch = text[from]; } glyphs.Add(GetGlyph(ch)); } } else { throw new PdfException("Font has no suitable cmap."); } } return(process); }