/** * Defines a glyph. * @param c the character to match this glyph. It must be one of those defined in the constructor * @param wx the advance this character will have * @param llx the X lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param lly the Y lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param urx the X upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param ury the Y upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @return a content where the glyph can be defined */ public PdfContentByte DefineGlyph(char c, float wx, float llx, float lly, float urx, float ury) { if (!char2byte.ContainsKey(c)) { throw new ArgumentException("The char " + (int)c + " doesn't belong in this Type3 font"); } Type3Glyph glyph = (Type3Glyph)char2glyph[c]; if (glyph != null) { return(glyph); } widths3[c] = (int)wx; if (!colorized) { if (float.IsNaN(this.llx)) { this.llx = llx; this.lly = lly; this.urx = urx; this.ury = ury; } else { this.llx = Math.Min(this.llx, llx); this.lly = Math.Min(this.lly, lly); this.urx = Math.Max(this.urx, urx); this.ury = Math.Max(this.ury, ury); } } glyph = new Type3Glyph(writer, pageResources, wx, llx, lly, urx, ury, colorized); char2glyph[c] = glyph; return(glyph); }
/// <summary> /// Defines a glyph. If the character was already defined it will return the same content /// true the value is ignored /// true the value is ignored /// true the value is ignored /// true the value is ignored /// </summary> /// <param name="c">the character to match this glyph.</param> /// <param name="wx">the advance this character will have</param> /// <param name="llx">the X lower left corner of the glyph bounding box. If the colorize option is</param> /// <param name="lly">the Y lower left corner of the glyph bounding box. If the colorize option is</param> /// <param name="urx">the X upper right corner of the glyph bounding box. If the colorize option is</param> /// <param name="ury">the Y upper right corner of the glyph bounding box. If the colorize option is</param> /// <returns>a content where the glyph can be defined</returns> public PdfContentByte DefineGlyph(char c, float wx, float llx, float lly, float urx, float ury) { if (c == 0 || c > 255) { throw new ArgumentException("The char " + (int)c + " doesn't belong in this Type3 font"); } _usedSlot[c] = true; Type3Glyph glyph = (Type3Glyph)_char2Glyph[c]; if (glyph != null) { return(glyph); } _widths3[c] = (int)wx; if (!_colorized) { if (float.IsNaN(_llx)) { _llx = llx; _lly = lly; _urx = urx; _ury = ury; } else { _llx = Math.Min(_llx, llx); _lly = Math.Min(_lly, lly); _urx = Math.Max(_urx, urx); _ury = Math.Max(_ury, ury); } } glyph = new Type3Glyph(_writer, _pageResources, wx, llx, lly, urx, ury, _colorized); _char2Glyph[c] = glyph; return(glyph); }
/** * Defines a glyph. If the character was already defined it will return the same content * @param c the character to match this glyph. * @param wx the advance this character will have * @param llx the X lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param lly the Y lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param urx the X upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param ury the Y upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @return a content where the glyph can be defined */ public PdfContentByte DefineGlyph(char c, float wx, float llx, float lly, float urx, float ury) { if (c == 0 || c > 255) { throw new ArgumentException(MessageLocalization.GetComposedMessage("the.char.1.doesn.t.belong.in.this.type3.font", (int)c)); } usedSlot[c] = true; Type3Glyph glyph = (Type3Glyph)char2glyph[c]; if (glyph != null) { return(glyph); } widths3[c] = (int)wx; if (!colorized) { if (float.IsNaN(this.llx)) { this.llx = llx; this.lly = lly; this.urx = urx; this.ury = ury; } else { this.llx = Math.Min(this.llx, llx); this.lly = Math.Min(this.lly, lly); this.urx = Math.Max(this.urx, urx); this.ury = Math.Max(this.ury, ury); } } glyph = new Type3Glyph(writer, pageResources, wx, llx, lly, urx, ury, colorized); char2glyph[c] = glyph; return(glyph); }
public PdfContentByte GetDuplicate() { Type3Glyph dup = new Type3Glyph(); dup.writer = writer; dup.pdf = pdf; dup.pageResources = pageResources; dup.colorized = colorized; return dup; }
public PdfContentByte GetDuplicate() { Type3Glyph dup = new Type3Glyph(); dup.writer = writer; dup.pdf = pdf; dup.pageResources = pageResources; dup.colorized = colorized; return(dup); }
/** * Defines a glyph. If the character was already defined it will return the same content * @param c the character to match this glyph. * @param wx the advance this character will have * @param llx the X lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param lly the Y lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param urx the X upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param ury the Y upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @return a content where the glyph can be defined */ public PdfContentByte DefineGlyph(char c, float wx, float llx, float lly, float urx, float ury) { if (c == 0 || c > 255) throw new ArgumentException(MessageLocalization.GetComposedMessage("the.char.1.doesn.t.belong.in.this.type3.font", (int)c)); usedSlot[c] = true; Type3Glyph glyph; char2glyph.TryGetValue(c, out glyph); if (glyph != null) return glyph; widths3[c] = (int)wx; if (!colorized) { if (float.IsNaN(this.llx)) { this.llx = llx; this.lly = lly; this.urx = urx; this.ury = ury; } else { this.llx = Math.Min(this.llx, llx); this.lly = Math.Min(this.lly, lly); this.urx = Math.Max(this.urx, urx); this.ury = Math.Max(this.ury, ury); } } glyph = new Type3Glyph(writer, pageResources, wx, llx, lly, urx, ury, colorized); char2glyph[c] = glyph; return glyph; }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, object[] oParams) { if (_writer != writer) { throw new ArgumentException("Type3 font used with the wrong PdfWriter"); } // Get first & lastchar ... int firstChar = 0; while (firstChar < _usedSlot.Length && !_usedSlot[firstChar]) { firstChar++; } if (firstChar == _usedSlot.Length) { throw new DocumentException("No glyphs defined for Type3 font"); } int lastChar = _usedSlot.Length - 1; while (lastChar >= firstChar && !_usedSlot[lastChar]) { lastChar--; } int[] localWidths = new int[lastChar - firstChar + 1]; int[] invOrd = new int[lastChar - firstChar + 1]; int invOrdIndx = 0, w = 0; for (int u = firstChar; u <= lastChar; u++, w++) { if (_usedSlot[u]) { invOrd[invOrdIndx++] = u; localWidths[w] = _widths3[u]; } } PdfArray diffs = new PdfArray(); PdfDictionary charprocs = new PdfDictionary(); int last = -1; for (int k = 0; k < invOrdIndx; ++k) { int c = invOrd[k]; if (c > last) { last = c; diffs.Add(new PdfNumber(last)); } ++last; int c2 = invOrd[k]; string s = GlyphList.UnicodeToName(c2); if (s == null) { s = "a" + c2; } PdfName n = new PdfName(s); diffs.Add(n); Type3Glyph glyph = (Type3Glyph)_char2Glyph[(char)c2]; PdfStream stream = new PdfStream(glyph.ToPdf(null)); stream.FlateCompress(compressionLevel); PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference; charprocs.Put(n, refp); } PdfDictionary font = new PdfDictionary(PdfName.Font); font.Put(PdfName.Subtype, PdfName.Type3); if (_colorized) { font.Put(PdfName.Fontbbox, new PdfRectangle(0, 0, 0, 0)); } else { font.Put(PdfName.Fontbbox, new PdfRectangle(_llx, _lly, _urx, _ury)); } font.Put(PdfName.Fontmatrix, new PdfArray(new[] { 0.001f, 0, 0, 0.001f, 0, 0 })); font.Put(PdfName.Charprocs, writer.AddToBody(charprocs).IndirectReference); PdfDictionary localEncoding = new PdfDictionary(); localEncoding.Put(PdfName.Differences, diffs); font.Put(PdfName.Encoding, writer.AddToBody(localEncoding).IndirectReference); font.Put(PdfName.Firstchar, new PdfNumber(firstChar)); font.Put(PdfName.Lastchar, new PdfNumber(lastChar)); font.Put(PdfName.Widths, writer.AddToBody(new PdfArray(localWidths)).IndirectReference); if (_pageResources.HasResources()) { font.Put(PdfName.Resources, writer.AddToBody(_pageResources.Resources).IndirectReference); } writer.AddToBody(font, piRef); }
/** * Defines a glyph. * @param c the character to match this glyph. It must be one of those defined in the constructor * @param wx the advance this character will have * @param llx the X lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param lly the Y lower left corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param urx the X upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @param ury the Y upper right corner of the glyph bounding box. If the <CODE>colorize</CODE> option is * <CODE>true</CODE> the value is ignored * @return a content where the glyph can be defined */ public PdfContentByte DefineGlyph(char c, float wx, float llx, float lly, float urx, float ury) { if (!char2byte.ContainsKey(c)) throw new ArgumentException("The char " + (int)c + " doesn't belong in this Type3 font"); Type3Glyph glyph = (Type3Glyph)char2glyph[c]; if (glyph != null) return glyph; widths3[c] = (int)wx; if (!colorized) { if (float.IsNaN(this.llx)) { this.llx = llx; this.lly = lly; this.urx = urx; this.ury = ury; } else { this.llx = Math.Min(this.llx, llx); this.lly = Math.Min(this.lly, lly); this.urx = Math.Max(this.urx, urx); this.ury = Math.Max(this.ury, ury); } } glyph = new Type3Glyph(writer, pageResources, wx, llx, lly, urx, ury, colorized); char2glyph[c] = glyph; return glyph; }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams) { if (this.writer != writer) { throw new ArgumentException("Type3 font used with the wrong PdfWriter"); } if (char2byte.Size != widths3.Size) { throw new DocumentException("Not all the glyphs in the Type3 font are defined"); } IntHashtable inv = new IntHashtable(); for (IntHashtable.IntHashtableIterator it = char2byte.GetEntryIterator(); it.HasNext();) { IntHashtable.IntHashtableEntry entry = it.Next(); inv[entry.Value] = entry.Key; } int[] invOrd = inv.ToOrderedKeys(); int firstChar = invOrd[0]; int lastChar = invOrd[invOrd.Length - 1]; int[] widths = new int[lastChar - firstChar + 1]; for (int k = 0; k < widths.Length; ++k) { if (inv.ContainsKey(k + firstChar)) { widths[k] = widths3[inv[k + firstChar]]; } } PdfArray diffs = new PdfArray(); PdfDictionary charprocs = new PdfDictionary(); int last = -1; for (int k = 0; k < invOrd.Length; ++k) { int c = invOrd[k]; if (c > last) { last = c; diffs.Add(new PdfNumber(last)); } ++last; int c2 = inv[c]; String s = GlyphList.UnicodeToName(c2); if (s == null) { s = "a" + c2; } PdfName n = new PdfName(s); diffs.Add(n); Type3Glyph glyph = (Type3Glyph)char2glyph[(char)c2]; PdfStream stream = new PdfStream(glyph.ToPdf(null)); stream.FlateCompress(); PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference; charprocs.Put(n, refp); } PdfDictionary font = new PdfDictionary(PdfName.FONT); font.Put(PdfName.SUBTYPE, PdfName.TYPE3); if (colorized) { font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0)); } else { font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); } font.Put(PdfName.FONTMATRIX, new PdfArray(new float[] { 0.001f, 0, 0, 0.001f, 0, 0 })); font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference); PdfDictionary encoding = new PdfDictionary(); encoding.Put(PdfName.DIFFERENCES, diffs); font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference); font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference); if (pageResources.HasResources()) { font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference); } writer.AddToBody(font, piRef); }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams) { if (this.writer != writer) { throw new ArgumentException("Type3 font used with the wrong PdfWriter"); } // Get first & lastchar ... int firstChar = 0; while (firstChar < usedSlot.Length && !usedSlot[firstChar]) { firstChar++; } if (firstChar == usedSlot.Length) { throw new DocumentException("No glyphs defined for Type3 font"); } int lastChar = usedSlot.Length - 1; while (lastChar >= firstChar && !usedSlot[lastChar]) { lastChar--; } int[] widths = new int[lastChar - firstChar + 1]; int[] invOrd = new int[lastChar - firstChar + 1]; int invOrdIndx = 0, w = 0; for (int u = firstChar; u <= lastChar; u++, w++) { if (usedSlot[u]) { invOrd[invOrdIndx++] = u; widths[w] = widths3[u]; } } PdfArray diffs = new PdfArray(); PdfDictionary charprocs = new PdfDictionary(); int last = -1; for (int k = 0; k < invOrdIndx; ++k) { int c = invOrd[k]; if (c > last) { last = c; diffs.Add(new PdfNumber(last)); } ++last; int c2 = invOrd[k]; String s = GlyphList.UnicodeToName(c2); if (s == null) { s = "a" + c2; } PdfName n = new PdfName(s); diffs.Add(n); Type3Glyph glyph = (Type3Glyph)char2glyph[(char)c2]; PdfStream stream = new PdfStream(glyph.ToPdf(null)); stream.FlateCompress(compressionLevel); PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference; charprocs.Put(n, refp); } PdfDictionary font = new PdfDictionary(PdfName.FONT); font.Put(PdfName.SUBTYPE, PdfName.TYPE3); if (colorized) { font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0)); } else { font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); } font.Put(PdfName.FONTMATRIX, new PdfArray(new float[] { 0.001f, 0, 0, 0.001f, 0, 0 })); font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference); PdfDictionary encoding = new PdfDictionary(); encoding.Put(PdfName.DIFFERENCES, diffs); font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference); font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference); if (pageResources.HasResources()) { font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference); } writer.AddToBody(font, piRef); }