Пример #1
0
        internal string GetFont(PDFResources resources, System.Windows.Media.GlyphTypeface typeFace)
        {
            string familyName = typeFace.FamilyNames.Values.FirstOrDefault();

            string key = null;

            if (!fonts.TryGetValue(typeFace, out key))
            {
                key = "R" + resources.ID + "F" + fonts.Count;
                PDFFont pf = PDFDocument.CreateObject <PDFFont>();
                pf.BaseFont         = familyName;
                pf.Subtype          = "Type1";
                pf.Encoding         = "MacRomanEncoding";
                resources.Font[key] = pf;

                var pd = PDFDocument.CreateObject <PDFFontDescriptor>();

                pf.FontDescriptor = pd;

                pd.FontName   = familyName;
                pd.FontFamily = familyName;
                pd.FontWeight = typeFace.Weight.ToOpenTypeWeight();


                pd.XHeight   = typeFace.XHeight;
                pd.CapHeight = typeFace.CapsHeight;
                pd.StemV     = typeFace.StrikethroughThickness;

                pd.Flags = PDFFontFlags.None;

                if (typeFace.Weight == FontWeights.Bold)
                {
                    pd.Flags |= PDFFontFlags.ForceBold;
                }

                if (typeFace.Symbol)
                {
                    pd.Flags |= PDFFontFlags.Symbolic;
                }
                else
                {
                    pd.Flags |= PDFFontFlags.Nonsymbolic;
                }
                pd.Ascent  = typeFace.AdvanceHeights.Select(x => x.Value).Max() - typeFace.Baseline;
                pd.Descent = -(typeFace.DistancesFromHorizontalBaselineToBlackBoxBottom.Select(x => x.Value).Max());

                pd.FontBBox        = new PDFRect();
                pd.FontBBox.Width  = (int)typeFace.AdvanceWidths.Select(x => x.Value).Sum();
                pd.FontBBox.Height = (int)typeFace.AdvanceHeights.Select(x => x.Value).Sum();

                fonts[typeFace] = key;
            }
            return(key);
        }
Пример #2
0
        internal string GetFont(PDFResources resources, System.Windows.Media.GlyphTypeface typeFace)
        {
            string familyName = typeFace.FamilyNames.Values.FirstOrDefault();

            string faceName = familyName;

            var fn = typeFace.FaceNames.Where(x => x.Key.LCID == System.Globalization.CultureInfo.CurrentCulture.LCID).Select(x => x.Value).FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(fn))
            {
                if (fn != "Regular")
                {
                    faceName += "," + fn;
                }
            }

            string key = null;

            if (!fonts.TryGetValue(faceName, out key))
            {
                key = "R" + resources.ID + "F" + fonts.Count;
                PDFFont pf = this.PDFDocument.CreateObject <PDFFont>();
                pf.BaseFont         = faceName;
                pf.Subtype          = "Type1";
                pf.Encoding         = "WinAnsiEncoding";
                resources.Font[key] = pf;

                //var pd = PDFDocument.CreateObject<PDFFontDescriptor>();

                //pf.FontDescriptor = pd;

                //pd.FontName = familyName;
                //pd.FontFamily = familyName;
                //pd.FontWeight = typeFace.Weight.ToOpenTypeWeight();


                //pd.XHeight = typeFace.XHeight;
                //pd.CapHeight = typeFace.CapsHeight;
                //pd.StemV = typeFace.StrikethroughThickness;

                //pd.Flags = PDFFontFlags.None;

                //if (typeFace.Weight == FontWeights.Bold)
                //{
                //    pd.Flags |= PDFFontFlags.ForceBold;
                //}

                //if (typeFace.Symbol)
                //{
                //    pd.Flags |= PDFFontFlags.Symbolic;
                //}
                //else
                //{
                //    pd.Flags |= PDFFontFlags.Nonsymbolic;
                //}
                //pd.Ascent = typeFace.AdvanceHeights.Select(x => x.Value).Max() - typeFace.Baseline;
                //pd.Descent = -(typeFace.DistancesFromHorizontalBaselineToBlackBoxBottom.Select(x => x.Value).Max());

                //pd.FontBBox = new PDFRect();
                //pd.FontBBox.Width = (int)typeFace.AdvanceWidths.Select(x => x.Value).Sum();
                //pd.FontBBox.Height = (int)typeFace.AdvanceHeights.Select(x => x.Value).Sum();

                fonts[faceName] = key;
            }
            return(key);
        }