示例#1
0
        private void AddFonts(IXpsFixedPageReader fixedPageReader, IXpsFixedPageWriter pageWriter)
        {
            // Adding font from source to resources.
            foreach (XpsFont font in fixedPageReader.Fonts)
            {
                if (!CheckIfFontAddedAlready(font.Uri.ToString()))
                {
                    XpsFont newFont = pageWriter.AddFont(false);

                    using (Stream dstFontStream = newFont.GetStream())
                    {
                        using (Stream srcFontStream = font.GetStream())
                        {
                            if (font.IsObfuscated)
                            {
                                WriteObfuscatedStream(font.Uri.ToString(),
                                                      dstFontStream, srcFontStream);
                            }
                            else
                            {
                                WriteToStream(dstFontStream, srcFontStream);
                            }
                            newFont.Commit();
                            XpsDetails xpsFont = new XpsDetails();
                            xpsFont.resource  = newFont;
                            xpsFont.sourceURI = font.Uri;
                            xpsFont.destURI   = newFont.Uri;
                            xpsFonts.Add(xpsFont);
                        }
                    }
                }
            }
        }
示例#2
0
        }// end:AddGlyphRun()

        // --------------------------- GetXpsFont() ---------------------------
        /// <summary>
        ///   Returns the relative path to a font part in the package.</summary>
        /// <param name="pageWriter">
        ///   The page to associate the font with.</param>
        /// <param name="fontUri">
        ///   The URI for the source font file.</param>
        /// <returns>
        ///   The relative path to font part in the package.</returns>
        /// <remarks>
        ///   If the font has not been added previously, GetXpsFont creates a
        ///   new font part and copies the font data from the specified
        ///   source font URI.</remarks>
        private string GetXpsFont(IXpsFixedPageWriter pageWriter, string fontUri)
        {
            string packageFontUri;

            if (_fontDictionary.ContainsKey(fontUri))
            {
                packageFontUri = _fontDictionary[fontUri];
            }
            else
            {
                XpsFont xpsFont   = pageWriter.AddFont(false);
                Stream  dstStream = xpsFont.GetStream();
                Stream  srcStream =
                    new FileStream(fontUri, FileMode.Open, FileAccess.Read);
                Byte[] streamBytes = new Byte[srcStream.Length];
                srcStream.Read(streamBytes, 0, (int)srcStream.Length);
                dstStream.Write(streamBytes, 0, (int)srcStream.Length);
                _fontDictionary[fontUri] = xpsFont.Uri.ToString();
                packageFontUri           = xpsFont.Uri.ToString();
                xpsFont.Commit();
            }
            return(packageFontUri);
        }// end:GetXpsFont()