Exemplo n.º 1
0
 public static FontEncoding CreateDocFontEncoding(PdfObject encoding, CMapToUnicode toUnicode)
 {
     if (encoding != null)
     {
         if (encoding.IsName())
         {
             return(FontEncoding.CreateFontEncoding(((PdfName)encoding).GetValue()));
         }
         else
         {
             if (encoding.IsDictionary())
             {
                 iText.Kernel.Font.DocFontEncoding fontEncoding = new iText.Kernel.Font.DocFontEncoding();
                 fontEncoding.differences = new String[256];
                 FillBaseEncoding(fontEncoding, ((PdfDictionary)encoding).GetAsName(PdfName.BaseEncoding));
                 FillDifferences(fontEncoding, ((PdfDictionary)encoding).GetAsArray(PdfName.Differences), toUnicode);
                 return(fontEncoding);
             }
         }
     }
     if (toUnicode != null)
     {
         iText.Kernel.Font.DocFontEncoding fontEncoding = new iText.Kernel.Font.DocFontEncoding();
         fontEncoding.differences = new String[256];
         FillDifferences(fontEncoding, toUnicode);
         return(fontEncoding);
     }
     else
     {
         return(FontEncoding.CreateFontSpecificEncoding());
     }
 }
Exemplo n.º 2
0
        internal PdfTrueTypeFont(TrueTypeFont ttf, String encoding, bool embedded)
            : base()
        {
            SetFontProgram(ttf);
            this.embedded = embedded;
            FontNames fontNames = ttf.GetFontNames();

            if (embedded && !fontNames.AllowEmbedding())
            {
                throw new PdfException("{0} cannot be embedded due to licensing restrictions.").SetMessageParams(fontNames
                                                                                                                 .GetFontName());
            }
            if ((encoding == null || encoding.Length == 0) && ttf.IsFontSpecific())
            {
                encoding = FontEncoding.FONT_SPECIFIC;
            }
            if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLowerInvariant().Equals(encoding.ToLowerInvariant()))
            {
                fontEncoding = FontEncoding.CreateFontSpecificEncoding();
            }
            else
            {
                fontEncoding = FontEncoding.CreateFontEncoding(encoding);
            }
        }
Exemplo n.º 3
0
        internal PdfTrueTypeFont(TrueTypeFont ttf, String encoding, bool embedded)
            : base()
        {
            SetFontProgram(ttf);
            this.embedded = embedded;
            FontNames fontNames = ttf.GetFontNames();

            if (embedded && !fontNames.AllowEmbedding())
            {
                throw new PdfException("1.cannot.be.embedded.due.to.licensing.restrictions").SetMessageParams(fontNames.GetFontName
                                                                                                                  ());
            }
            if ((encoding == null || encoding.Length == 0) && ttf.IsFontSpecific())
            {
                encoding = FontEncoding.FONT_SPECIFIC;
            }
            if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLower(System.Globalization.CultureInfo.InvariantCulture
                                                                       ).Equals(encoding.ToLower(System.Globalization.CultureInfo.InvariantCulture)))
            {
                fontEncoding = FontEncoding.CreateFontSpecificEncoding();
            }
            else
            {
                fontEncoding = FontEncoding.CreateFontEncoding(encoding);
            }
        }
Exemplo n.º 4
0
 internal PdfType1Font(Type1Font type1Font, String encoding, bool embedded)
     : base()
 {
     SetFontProgram(type1Font);
     this.embedded = embedded && !type1Font.IsBuiltInFont();
     if ((encoding == null || encoding.Length == 0) && type1Font.IsFontSpecific())
     {
         encoding = FontEncoding.FONT_SPECIFIC;
     }
     if (encoding != null && FontEncoding.FONT_SPECIFIC.ToLowerInvariant().Equals(encoding.ToLowerInvariant()))
     {
         fontEncoding = FontEncoding.CreateFontSpecificEncoding();
     }
     else
     {
         fontEncoding = FontEncoding.CreateFontEncoding(encoding);
     }
 }
Exemplo n.º 5
0
        /// <summary>Returns the Font.</summary>
        /// <returns>the font</returns>
        /// <exception cref="System.IO.IOException"/>
        public virtual FontProgram GetFont()
        {
            if (font != null)
            {
                return(font);
            }
            FontProgram ff2 = FontProgramFactory.CreateRegisteredFont(faceName, ((italic != 0) ? FontConstants.ITALIC :
                                                                                 0) | ((bold != 0) ? FontConstants.BOLD : 0));

            encoding = FontEncoding.CreateFontEncoding(PdfEncodings.WINANSI);
            font     = ff2;
            if (font != null)
            {
                return(font);
            }
            String fontName;

            if (faceName.Contains("courier") || faceName.Contains("terminal") || faceName.Contains("fixedsys"))
            {
                fontName = fontNames[MARKER_COURIER + italic + bold];
            }
            else
            {
                if (faceName.Contains("ms sans serif") || faceName.Contains("arial") || faceName.Contains("system"))
                {
                    fontName = fontNames[MARKER_HELVETICA + italic + bold];
                }
                else
                {
                    if (faceName.Contains("arial black"))
                    {
                        fontName = fontNames[MARKER_HELVETICA + italic + MARKER_BOLD];
                    }
                    else
                    {
                        if (faceName.Contains("times") || faceName.Contains("ms serif") || faceName.Contains("roman"))
                        {
                            fontName = fontNames[MARKER_TIMES + italic + bold];
                        }
                        else
                        {
                            if (faceName.Contains("symbol"))
                            {
                                fontName = fontNames[MARKER_SYMBOL];
                            }
                            else
                            {
                                int pitch  = pitchAndFamily & 3;
                                int family = (pitchAndFamily >> 4) & 7;
                                switch (family)
                                {
                                case FF_MODERN: {
                                    fontName = fontNames[MARKER_COURIER + italic + bold];
                                    break;
                                }

                                case FF_ROMAN: {
                                    fontName = fontNames[MARKER_TIMES + italic + bold];
                                    break;
                                }

                                case FF_SWISS:
                                case FF_SCRIPT:
                                case FF_DECORATIVE: {
                                    fontName = fontNames[MARKER_HELVETICA + italic + bold];
                                    break;
                                }

                                default: {
                                    switch (pitch)
                                    {
                                    case FIXED_PITCH: {
                                        fontName = fontNames[MARKER_COURIER + italic + bold];
                                        break;
                                    }

                                    default: {
                                        fontName = fontNames[MARKER_HELVETICA + italic + bold];
                                        break;
                                    }
                                    }
                                    break;
                                }
                                }
                            }
                        }
                    }
                }
            }
            try {
                font     = FontProgramFactory.CreateFont(fontName);
                encoding = FontEncoding.CreateFontEncoding(PdfEncodings.WINANSI);
            }
            catch (System.IO.IOException e) {
                throw new Exception(e.Message, e);
            }
            return(font);
        }