コード例 #1
0
        private Font LoadCIDFont()
        {
            switch (fontType)
            {
            case FontType.Embed:
                realFont = new Type2CIDFont(properties);
                break;

            case FontType.Subset:
                realFont = new Type2CIDSubsetFont(properties);
                break;
            }

            // Flag that indicates whether the CID font should be replaced by a
            // base 14 font due to a license violation
            bool replaceFont = false;

            IFontDescriptor descriptor = realFont.Descriptor;

            if (!descriptor.IsEmbeddable)
            {
                PdfCreatorBridge.Warning(
                    String.Format("Unable to embed font '{0}' because the license states embedding is not allowed.  Will default to Helvetica.",
                                  realFont.FontName));

                replaceFont = true;
            }

            // TODO: Do not permit subsetting if license does not allow it
            if (realFont is Type2CIDSubsetFont && !descriptor.IsSubsettable)
            {
                PdfCreatorBridge.Warning(
                    String.Format("Unable to subset font '{0}' because the license states subsetting is not allowed..  Will default to Helvetica.",
                                  realFont.FontName));

                replaceFont = true;
            }

            if (replaceFont)
            {
                if (properties.IsBoldItalic)
                {
                    realFont = Base14Font.HelveticaBoldItalic;
                }
                else if (properties.IsBold)
                {
                    realFont = Base14Font.HelveticaBold;
                }
                else if (properties.IsItalic)
                {
                    realFont = Base14Font.HelveticaItalic;
                }
                else
                {
                    realFont = Base14Font.Helvetica;
                }
            }

            return(realFont);
        }
コード例 #2
0
ファイル: FontInfo.cs プロジェクト: jps1974/SaveAsPdf
        private string FontLookup(string key)
        {
            string f = (string)triplets[key];

            if (f == null)
            {
                int    i = key.IndexOf(',');
                string s = "any" + key.Substring(i);
                f = (string)triplets[s];
                if (f == null)
                {
                    f = (string)triplets["any,normal,normal"];
                    if (f == null)
                    {
                        PdfCreatorBridge.Error("no default font defined by OutputConverter");
                    }
                    PdfCreatorBridge.Msg(
                        "Defaulted font to any,normal,normal");
                }
                PdfCreatorBridge.Warning(
                    "Unknown font " + key + " so defaulted font to any");
            }

            usedFonts[f] = fonts[f];
            return(f);
        }
コード例 #3
0
ファイル: FontSetup.cs プロジェクト: jps1974/SaveAsPdf
        /// <summary>
        ///     Adds all the system fonts to the FontInfo object.
        /// </summary>
        /// <remarks>
        ///     Adds metrics for basic fonts and useful family-style-weight
        ///     triplets for lookup.
        /// </remarks>
        /// <param name="fontType">Determines what type of font to instantiate.</param>
        private void AddSystemFonts(FontType fontType)
        {
            GdiFontEnumerator enumerator = new GdiFontEnumerator(new GdiDeviceContent());

            foreach (string familyName in enumerator.FamilyNames)
            {
                if (IsBase14FontName(familyName))
                {
                    PdfCreatorBridge.Warning(
                        "Will ignore TrueType font '" + familyName + "' because a base 14 font with the same name already exists.");
                }
                else
                {
                    FontStyles styles = enumerator.GetStyles(familyName);

                    string name = GetNextAvailableName();
                    fontInfo.AddMetrics(name, new ProxyFont(new FontProperties(familyName, false, false), fontType));
                    fontInfo.AddFontProperties(name, familyName, "normal", "normal");

                    name = GetNextAvailableName();
                    fontInfo.AddMetrics(name, new ProxyFont(new FontProperties(familyName, true, false), fontType));
                    fontInfo.AddFontProperties(name, familyName, "normal", "bold");

                    name = GetNextAvailableName();
                    fontInfo.AddMetrics(name, new ProxyFont(new FontProperties(familyName, false, true), fontType));
                    fontInfo.AddFontProperties(name, familyName, "italic", "normal");

                    name = GetNextAvailableName();
                    fontInfo.AddMetrics(name, new ProxyFont(new FontProperties(familyName, true, true), fontType));
                    fontInfo.AddFontProperties(name, familyName, "italic", "bold");
                }
            }

            // Cursive - Monotype Corsiva
            fontInfo.AddMetrics("F15", new ProxyFont(new FontProperties("Monotype Corsiva", false, false), fontType));
            fontInfo.AddFontProperties("F15", "cursive", "normal", "normal");

            // Fantasy - Zapf Dingbats
            fontInfo.AddMetrics("F16", Base14Font.ZapfDingbats);
            fontInfo.AddFontProperties("F16", "fantasy", "normal", "normal");
        }
コード例 #4
0
ファイル: ColorType.cs プロジェクト: jps1974/SaveAsPdf
        public ColorType(string value)
        {
            string colorValue = value.ToLower();

            if (colorValue.StartsWith("#"))
            {
                try
                {
                    if (colorValue.Length == 4)
                    {
                        // note: divide by 15 so F = FF = 1 and so on
                        red = Int32.Parse(
                            colorValue.Substring(1, 1), NumberStyles.HexNumber) / 15f;
                        green = Int32.Parse(
                            colorValue.Substring(2, 1), NumberStyles.HexNumber) / 15f;
                        blue = Int32.Parse(
                            colorValue.Substring(3, 1), NumberStyles.HexNumber) / 15f;
                    }
                    else if (colorValue.Length == 7)
                    {
                        // note: divide by 255 so FF = 1
                        red = Int32.Parse(
                            colorValue.Substring(1, 2), NumberStyles.HexNumber) / 255f;
                        green = Int32.Parse(
                            colorValue.Substring(3, 2), NumberStyles.HexNumber) / 255f;
                        blue = Int32.Parse(
                            colorValue.Substring(5, 2), NumberStyles.HexNumber) / 255f;
                    }
                    else
                    {
                        red   = 0;
                        green = 0;
                        blue  = 0;
                        PdfCreatorBridge.Error(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }
                catch (Exception)
                {
                    red   = 0;
                    green = 0;
                    blue  = 0;
                    PdfCreatorBridge.Error(
                        "Unknown colour format. Must be #RGB or #RRGGBB");
                }
            }
            else if (colorValue.StartsWith("rgb("))
            {
                int poss = colorValue.IndexOf("(");
                int pose = colorValue.IndexOf(")");
                if (poss != -1 && pose != -1)
                {
                    colorValue = colorValue.Substring(poss + 1, pose);
                    StringTokenizer st = new StringTokenizer(colorValue, ",");
                    try
                    {
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Red =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Red = Int32.Parse(str) / 255f;
                            }
                        }
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Green =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Green = Int32.Parse(str) / 255f;
                            }
                        }
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Blue =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Blue = Int32.Parse(str) / 255f;
                            }
                        }
                    }
                    catch
                    {
                        this.Red   = 0;
                        this.Green = 0;
                        this.Blue  = 0;
                        PdfCreatorBridge.Error(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }
            }
            else if (colorValue.StartsWith("url("))
            {
                // refers to a gradient
                PdfCreatorBridge.Error(
                    "unsupported color format");
            }
            else
            {
                if (colorValue.Equals("transparent"))
                {
                    Red   = 0;
                    Green = 0;
                    Blue  = 0;
                    Alpha = 1;
                }
                else
                {
                    bool found = false;
                    for (int count = 0; count < names.Length; count++)
                    {
                        if (colorValue.Equals(names[count]))
                        {
                            Red   = vals[count, 0] / 255f;
                            Green = vals[count, 1] / 255f;
                            Blue  = vals[count, 2] / 255f;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Red   = 0;
                        Green = 0;
                        Blue  = 0;
                        PdfCreatorBridge.Warning(
                            "Unknown colour name: " + colorValue + ".  Defaulting to black.");
                    }
                }
            }
        }
コード例 #5
0
        //internal static FonetImage MakeFromResource(string key)
        //{

        //    Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(key);
        //    byte[] buffer = new byte[s.Length];
        //    s.Read(buffer, 0, buffer.Length);

        //    return new FonetImage("file://" + key, buffer);
        //}

        /// <summary>
        ///     Creates a FonetImage from the supplied resource locator.  The
        ///     FonetImageFactory does cache images, therefore this method may
        ///     return a reference to an existing FonetImage
        /// </summary>
        /// <param name="href">A Uniform Resource Identifier</param>
        /// <returns>A reference to a  FonetImage</returns>
        /// <exception cref="FonetImageException"></exception>
        public static FonetImage Make(string href)
        {
            return(PdfCreatorBridge.LoadImage(href));
        }