Exemplo n.º 1
0
        protected override Encoding ReadEncodingFromFont()
        {
            if (!IsEmbedded && Standard14AFM != null)
            {
                // read from AFM
                return(new Type1Encoding(Standard14AFM));
            }
            else
            {
                // non-symbolic fonts don't have a built-in encoding per se, but there encoding is
                // assumed to be StandardEncoding by the PDF spec unless an explicit Encoding is present
                // which will override this anyway
                if (!(SymbolicFlag ?? true))
                {
                    return(StandardEncoding.Instance);
                }

                // normalise the standard 14 name, e.g "Symbol,Italic" -> "Symbol"
                string standard14Name = Standard14Fonts.GetMappedFontName(Name);

                // likewise, if the font is standard 14 then we know it's Standard Encoding
                if (IsStandard14 &&
                    !standard14Name.Equals("Symbol", StringComparison.Ordinal) &&
                    !standard14Name.Equals("ZapfDingbats", StringComparison.Ordinal))
                {
                    return(StandardEncoding.Instance);
                }

                // synthesize an encoding, so that getEncoding() is always usable
                PostScriptTable          post       = ttf.PostScript;
                Dictionary <int, string> codeToName = new Dictionary <int, string>();
                for (int code = 0; code <= 256; code++)
                {
                    int gid = CodeToGID(code);
                    if (gid > 0)
                    {
                        string name = null;
                        if (post != null)
                        {
                            name = post.GetName(gid);
                        }
                        if (name == null)
                        {
                            // GID pseudo-name
                            name = gid.ToString();
                        }
                        codeToName[code] = name;
                    }
                }
                return(new BuiltInEncoding(codeToName));
            }
        }
Exemplo n.º 2
0
        public FontMapperImpl()
        {
            // substitutes for standard 14 fonts
            substitutes.Add("Courier", new List <string> {
                "CourierNew", "CourierNewPSMT", "LiberationMono", "NimbusMonL-Regu"
            });
            substitutes.Add("Courier-Bold", new List <string> {
                "CourierNewPS-BoldMT", "CourierNew-Bold", "LiberationMono-Bold", "NimbusMonL-Bold"
            });
            substitutes.Add("Courier-Oblique", new List <string> {
                "CourierNewPS-ItalicMT", "CourierNew-Italic", "LiberationMono-Italic", "NimbusMonL-ReguObli"
            });
            substitutes.Add("Courier-BoldOblique", new List <string> {
                "CourierNewPS-BoldItalicMT", "CourierNew-BoldItalic", "LiberationMono-BoldItalic", "NimbusMonL-BoldObli"
            });
            substitutes.Add("Helvetica", new List <string> {
                "ArialMT", "Arial", "LiberationSans", "NimbusSanL-Regu"
            });
            substitutes.Add("Helvetica-Bold", new List <string> {
                "Arial-BoldMT", "Arial-Bold", "LiberationSans-Bold", "NimbusSanL-Bold"
            });
            substitutes.Add("Helvetica-Oblique", new List <string> {
                "Arial-ItalicMT", "Arial-Italic", "Helvetica-Italic", "LiberationSans-Italic", "NimbusSanL-ReguItal"
            });
            substitutes.Add("Helvetica-BoldOblique", new List <string> {
                "Arial-BoldItalicMT", "Helvetica-BoldItalic", "LiberationSans-BoldItalic", "NimbusSanL-BoldItal"
            });
            substitutes.Add("Times-Roman", new List <string> {
                "TimesNewRomanPSMT", "TimesNewRoman", "TimesNewRomanPS", "LiberationSerif", "NimbusRomNo9L-Regu"
            });
            substitutes.Add("Times-Bold", new List <string> {
                "TimesNewRomanPS-BoldMT", "TimesNewRomanPS-Bold", "TimesNewRoman-Bold", "LiberationSerif-Bold", "NimbusRomNo9L-Medi"
            });
            substitutes.Add("Times-Italic", new List <string> {
                "TimesNewRomanPS-ItalicMT", "TimesNewRomanPS-Italic", "TimesNewRoman-Italic", "LiberationSerif-Italic", "NimbusRomNo9L-ReguItal"
            });
            substitutes.Add("Times-BoldItalic", new List <string> {
                "TimesNewRomanPS-BoldItalicMT", "TimesNewRomanPS-BoldItalic", "TimesNewRoman-BoldItalic", "LiberationSerif-BoldItalic", "NimbusRomNo9L-MediItal"
            });
            substitutes.Add("Symbol", new List <string> {
                "Symbol", "SymbolMT", "StandardSymL"
            });
            substitutes.Add("ZapfDingbats", new List <string> {
                "ZapfDingbatsITCbyBT-Regular", "ZapfDingbatsITC", "Dingbats", "MS-Gothic"
            });

            // Acrobat also uses alternative names for Standard 14 fonts, which we map to those above
            // these include names such as "Arial" and "TimesNewRoman"
            foreach (string baseName in Standard14Fonts.Names)
            {
                if (!substitutes.ContainsKey(baseName))
                {
                    string mappedName = Standard14Fonts.GetMappedFontName(baseName);
                    substitutes.Add(baseName, CopySubstitutes(mappedName));
                }
            }

            // -------------------------

            try
            {
                string ttfName   = "fonts.ttf.LiberationSans-Regular";
                var    ttfStream = typeof(IFontMapper).Assembly.GetManifestResourceStream(ttfName);
                if (ttfStream == null)
                {
                    throw new IOException("Error loading resource: " + ttfName);
                }
                TTFParser ttfParser = new TTFParser();
                lastResortFont = ttfParser.Parse(ttfStream);
            }
            catch (IOException e)
            {
                throw new Exception("Load LiberationSans", e);
            }
        }