Ejemplo n.º 1
0
        public static void Run(string outputPdfPath)
        {
            // Create a document and set it's properties
            Document document = new Document
            {
                Creator = "HelloWorldLanguages",
                Author  = "ceTe Software",
                Title   = "Hello World Languages"
            };

            Font japansesFont           = Font.HeiseiKakuGothicW5;
            Font koreanFont             = Font.HanyangSystemsGothicMedium;
            Font chineseSimplifiedFont  = Font.SinoTypeSongLight;
            Font chineseTraditionalFont = Font.MonotypeHeiMedium;
            Font latin1Font             = Font.TimesRoman;
            Font unicodeFont            = new OpenTypeFont("times.ttf");

            Font unicodeFont1 = new OpenTypeFont("micross.ttf", true);
            Font InFont       = new OpenTypeFont("Nirmala.ttf", true);

            // Create a page to add to the document
            Page page  = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
            Page page1 = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);

            // Uncomment the line below to add a layout grid to the page
            //page.Elements.Add( new LayoutGrid() );

            // Add label to page
            AddLanguage(page, 1, 1, "Dutch:", "Hallo", latin1Font);
            AddLanguage(page, 2, 1, "English:", "Hello", latin1Font);
            AddLanguage(page, 1, 2, "French:", "Bonjour", latin1Font);
            AddLanguage(page, 2, 2, "German:", "Hallo", latin1Font);
            AddLanguage(page, 1, 3, "Greek:", "Χαίρετε", unicodeFont);
            AddLanguage(page, 2, 3, "Italian:", "Ciao", latin1Font);
            AddLanguage(page, 1, 4, "Japanese:", "こんにちは", japansesFont);
            AddLanguage(page, 2, 4, "Korean:", "안녕하세요", koreanFont);
            AddLanguage(page, 1, 5, "Norwegian:", "Hallo", latin1Font);
            AddLanguage(page, 2, 5, "Portuguese:", "Olá", latin1Font);
            AddLanguage(page, 1, 6, "Russian:", "Здравствуйте", unicodeFont);
            AddLanguage(page, 2, 6, "Simplified Chinese:", "你好", chineseSimplifiedFont);
            AddLanguage(page, 1, 7, "Spanish:", "Hola", latin1Font);
            AddLanguage(page, 2, 7, "Traditional Chinese:", "你好", chineseTraditionalFont);

            AddLanguage(page1, 1, 1, "Arabic:", "مرحبا", unicodeFont1);
            AddLanguage(page1, 2, 1, "Hebrew:", "שלום", unicodeFont1);
            AddLanguage(page1, 1, 2, "Thai:", "สวัสดี", unicodeFont1);
            AddLanguage(page1, 2, 2, "Hindi:", "नमस्ते", InFont);
            AddLanguage(page1, 1, 3, "Bangla:", "স্বাগত", InFont);
            AddLanguage(page1, 2, 3, "Tamil:", "வணக்கம்", InFont);


            // Add pages to document
            document.Pages.Add(page);
            document.Pages.Add(page1);

            // Outputs the document to the current web page
            document.Draw(outputPdfPath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the specified font.
        /// </summary>
        /// <param name="font">The font.</param>
        /// <returns></returns>
        public static PdfFont Create(BaseFont font)
        {
            if (font is AdobeStandardFont)
            {
                return(new PdfType1Font(font));
            }
            if (font is OpenTypeFont)
            {
                OpenTypeFont font2 = font as OpenTypeFont;
                switch (font.Encoding)
                {
                case "WinAnsiEncoding":
                    if (!font2.IsCFF)
                    {
                        return(new PdfTrueTypeFont(font));
                    }
                    return(new PdfType1Font(font));

                case "Identity-H":
                case "Identity-V":
                    return(new PdfType0Font(font));

                case "UniGB-UCS2-H":
                case "UniCNS-UCS2-H":
                case "UniJIS-UCS2-H":
                case "UniKS-UCS2-H":
                    return(new PdfType0Font(font));
                }
            }
            if (font is SimpleTrueTypeFont)
            {
                switch (font.Encoding)
                {
                case "WinAnsiEncoding":
                    return(new PdfTrueTypeFont(font));

                case "Identity-H":
                case "Identity-V":
                    throw new PdfNotSupportedException();

                case "UniGB-UCS2-H":
                case "UniCNS-UCS2-H":
                case "UniJIS-UCS2-H":
                case "UniKS-UCS2-H":
                    return(new PdfType0Font(font));
                }
            }
            throw new NotSupportedException();
        }
        private static IEnumerable <FontInfo> AddFontFileToCache(Dictionary <string, List <FontInfo> > cache, Dictionary <string, FontInfo> fullCache, string path)
        {
            FontInfo AddFont(OpenTypeFont font)
            {
#if DEBUG
                Logger.log.Debug($"'{path}' = '{font.Family}' '{font.Subfamily}' ({font.FullName})");
#endif
                var fontInfo = new FontInfo(path, font);

                var list = GetListForFamily(cache, font.Family);
                list.Add(fontInfo);
                var name = font.FullName;
                if (fullCache.ContainsKey(name))
                {
                    // Beat Saber 1.13.4 includes well over 100+ fonts that most systems have, this completely blows up the console on game launch.
                    // Logger.log.Warn($"Duplcicate font with full name '{name}' at {path}");
                }
                else
                {
                    fullCache.Add(name, fontInfo);
                }
                return(fontInfo);
            }

            using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
            using var reader     = OpenTypeReader.For(fileStream);
            if (reader is OpenTypeCollectionReader colReader)
            {
                var collection = new OpenTypeCollection(colReader, lazyLoad: false);
                return(collection.Select(AddFont).ToList());
            }
            else if (reader is OpenTypeFontReader fontReader)
            {
                var font = new OpenTypeFont(fontReader, lazyLoad: false);
                return(Utilities.SingleEnumerable(AddFont(font)));
            }
            else
            {
                Logger.log.Warn($"Font file '{path}' is not an OpenType file");
                return(Enumerable.Empty <FontInfo>());
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PdfType1Font" /> class.
 /// </summary>
 /// <param name="baseFont">The base font.</param>
 public PdfType1Font(BaseFont baseFont) : base(PdfName.Type1, baseFont)
 {
     if (baseFont is AdobeStandardFont)
     {
         base.isStandard   = true;
         base.baseFontName = ((AdobeStandardFont)baseFont).GetPdfName();
     }
     else
     {
         if (!(baseFont is OpenTypeFont))
         {
             throw new PdfNotSupportedException();
         }
         OpenTypeFont font = baseFont as OpenTypeFont;
         if (!font.IsCFF)
         {
             throw new PdfArgumentException("Not a CFF OpenType font.");
         }
     }
     this.InitPdfFontDescriptor();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PdfType0Font" /> class.
 /// </summary>
 /// <param name="baseFont">The base font.</param>
 public PdfType0Font(BaseFont baseFont) : base(PdfName.Type0, baseFont)
 {
     if (baseFont == null)
     {
         throw new PdfArgumentNullException("baseFont");
     }
     if (baseFont is OpenTypeFont)
     {
         OpenTypeFont font = baseFont as OpenTypeFont;
         this.cidFont = font.IsCFF ? new PdfCIDFont(PdfName.CIDFontType0, baseFont) : new PdfCIDFont(PdfName.CIDFontType2, baseFont);
         base[PdfName.DescendantFonts] = new PdfArray(new PdfCIDFont[] { this.cidFont });
     }
     else
     {
         if (!(baseFont is SimpleTrueTypeFont))
         {
             throw new PdfNotSupportedException("Didn't support this font");
         }
         this.cidFont = new PdfCIDFont(PdfName.CIDFontType2, baseFont);
         base[PdfName.DescendantFonts] = new PdfArray(new PdfCIDFont[] { this.cidFont });
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the font.
        /// </summary>
        /// <param name="font">The font</param>
        /// <returns></returns>
        internal BaseFont GetFont(Font font)
        {
            font = font ?? this.defaultFont;
            if (string.IsNullOrEmpty(font.FontFamilyName))
            {
                font            = (Font)font.Clone();
                font.FontFamily = this.defaultFont.FontFamily;
            }
            string str = string.Format("{0},{1}", (object[])new object[] { font.FontFamilyName, font.FontStyleType });

            if (this.fontCaches.ContainsKey(str))
            {
                return(this.fontCaches[str]);
            }
            BaseFont arialMT = null;

            byte[] data = null;
            switch (font.FontFamilyName)
            {
            case "Arial":
                arialMT = SimpleTrueTypeFont.ArialMT;
                break;

            case "Arial Black":
                arialMT = SimpleTrueTypeFont.ArialBlack;
                break;

            case "Arial Narrow":
                arialMT = SimpleTrueTypeFont.ArialNarrow;
                break;

            case "Comic Sans MS":
                arialMT = SimpleTrueTypeFont.ComicSansMS;
                break;

            case "Courier New":
                arialMT = SimpleTrueTypeFont.CourierNewPSMT;
                break;

            case "Georgia":
                arialMT = SimpleTrueTypeFont.Georgia;
                break;

            case "Lucida Sans Unicode":
                arialMT = SimpleTrueTypeFont.LucidaSansUnicode;
                break;

            case "Times New Roman":
                arialMT = SimpleTrueTypeFont.TimesNewRomanPSMT;
                break;

            case "Trebuchet MS":
                arialMT = SimpleTrueTypeFont.TrebuchetMS;
                break;

            case "Verdana":
                arialMT = SimpleTrueTypeFont.Verdana;
                break;

            case "Webdings":
                arialMT = SimpleTrueTypeFont.Webdings;
                break;

            case "Portable User Interface":
                arialMT = SimpleTrueTypeFont.Verdana;
                break;

            case "Microsoft Sans Serif":
                arialMT = SimpleTrueTypeFont.MicrosoftSansSerif;
                break;

            case "SimSun":
                arialMT = SimpleTrueTypeFont.SimSun;
                break;

            case "MS Mincho":
                arialMT = SimpleTrueTypeFont.MSMincho;
                break;

            case "Batang":
                arialMT = SimpleTrueTypeFont.Batang;
                break;
            }
            if ((arialMT == null) && (this.ExternalFont != null))
            {
                ExternalFontEventArgs args = new ExternalFontEventArgs(font.FontFamilyName);
                this.ExternalFont(this, args);
                data = args.FontData;
                if (args.SimpleTrueTypeFont != null)
                {
                    arialMT = args.SimpleTrueTypeFont;
                }
                else if ((data != null) && (data.Length > 0))
                {
                    arialMT            = OpenTypeFont.Load(new OpenTypeFontReader(data));
                    arialMT.Encoding   = "Identity-H";
                    arialMT.IsEmbedded = true;
                }
            }
            // hdt 原来Verdana
            if (arialMT == null)
            {
                arialMT = SimpleTrueTypeFont.SimSun;
            }
            this.fontCaches.Add(str, arialMT);
            return(arialMT);
        }
 public FontInfo(string path, OpenTypeFont info)
 {
     Path = path;
     Info = info;
 }