Beispiel #1
0
        private WW.Pdf.Font.Font method_1()
        {
            switch (this.fontType_0)
            {
            case FontType.Embed:
                this.font_0 = (WW.Pdf.Font.Font) new Class31(this.fontProperties_0);
                break;

            case FontType.Subset:
                this.font_0 = (WW.Pdf.Font.Font) new Class32(this.fontProperties_0);
                break;
            }
            bool            flag       = false;
            IFontDescriptor descriptor = this.font_0.Descriptor;

            if (!descriptor.IsEmbeddable)
            {
                flag = true;
            }
            if (this.font_0 is Class32 && !descriptor.IsSubsettable)
            {
                flag = true;
            }
            if (flag)
            {
                this.font_0 = !this.fontProperties_0.IsBoldItalic ? (!this.fontProperties_0.IsBold ? (!this.fontProperties_0.IsItalic ? Class14.font_4 : Class14.font_6) : Class14.font_5) : Class14.font_7;
            }
            return(this.font_0);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// Draw a string with the given font at the given location.
        /// </summary>
        /// <param name="text">The string to write.</param>
        /// <param name="font">The font to use to draw.  This must be a <see cref="FontDescriptor"/> object.</param>
        /// <param name="x">X coordinate of the top-left corner of the drawn string.</param>
        /// <param name="y">Y coordinate of the top-left corner of the drawn string.</param>
        /// <exception cref="ArgumentException" />Thrown if the <see cref="IFontDescriptor" /> parameter is not a <see cref="FontDescriptor" /> object.
        public void DrawString(string text, IFontDescriptor font, double x, double y)
        {
            if (!(font is FontDescriptor ourFont))
            {
                throw new ArgumentException(Resources.Error_FontDescriptorOfWrongSpecificType, nameof(font));
            }

            _core.DrawString(text, ourFont.Font, XBrushes.Black, x, y);
        }
        public void WordClass_MakeWordsMethod_ThrowsArgumentNullException_IfFirstParameterIsNotNullAndSecondParameterIsNull()
        {
            string           testParam0 = _rnd.NextString(_rnd.Next(300));
            IFontDescriptor  testParam1 = null;
            IGraphicsContext testParam2 = new Mock <IGraphicsContext>().Object;

            _ = Word.MakeWords(testParam0, testParam1, testParam2).ToArray();

            Assert.Fail();
        }
Beispiel #5
0
        /// <summary>
        /// Measures the dimensions of a string drawn using this graphics context in a given font.
        /// </summary>
        /// <param name="text">The text to measure.</param>
        /// <param name="font">The font to use to render the string.  Must be a <see cref="FontDescriptor"/> object.</param>
        /// <returns>The dimensions of the string when rendered.</returns>
        /// <exception cref="ArgumentException" />Thrown if the <see cref="IFontDescriptor" /> paramter is not a <see cref="FontDescriptor" /> instance.
        public UniSize MeasureString(string text, IFontDescriptor font)
        {
            if (!(font is FontDescriptor ourFont))
            {
                throw new ArgumentException(Resources.Error_FontDescriptorOfWrongSpecificType, nameof(font));
            }

            var size = _core.MeasureString(text, ourFont.Font);

            return(new UniSize(size.Width, size.Height));
        }
Beispiel #6
0
        /// <summary>
        ///     Creates a character indexed font from <i>cidFont</i>
        /// </summary>
        /// <remarks>
        ///     The <i>font</i> and <i>cidFont</i> will be different object
        ///     references since the <i>font</i> parameter will most likely
        ///     be a <see cref="ProxyFont"/>.
        /// </remarks>
        /// <param name="pdfFontID">The Pdf font identifier, e.g. F15</param>
        /// <param name="font">Required to access the font descriptor.</param>
        /// <param name="cidFont">The underlying CID font.</param>
        /// <returns></returns>
        private PdfFont CreateCIDFont(
            string pdfFontID, Font font, CIDFont cidFont)
        {
            // The font descriptor is required to access licensing details are
            // obtain the font program itself as a byte array
            IFontDescriptor descriptor = font.Descriptor;

            // A compressed stream that stores the font program
            PdfFontFile fontFile = new PdfFontFile(
                NextObjectId(), descriptor.FontData);

            // Add indirect reference to FontFile object to descriptor
            PdfFontDescriptor pdfDescriptor = MakeFontDescriptor(pdfFontID, cidFont);

            pdfDescriptor.FontFile2 = fontFile;

            PdfCIDSystemInfo pdfCidSystemInfo = new PdfCIDSystemInfo(
                cidFont.Registry, cidFont.Ordering, cidFont.Supplement);

            PdfCIDFont pdfCidFont = new PdfCIDFont(
                NextObjectId(), PdfFontSubTypeEnum.CIDFontType2, font.FontName);

            pdfCidFont.SystemInfo   = pdfCidSystemInfo;
            pdfCidFont.Descriptor   = pdfDescriptor;
            pdfCidFont.DefaultWidth = new PdfNumeric(cidFont.DefaultWidth);
            pdfCidFont.Widths       = cidFont.WArray;

            // Create a ToUnicode CMap that maps characters codes (GIDs) to
            // unicode values.  Very important to ensure searching and copying
            // from a PDF document works correctly.
            PdfCMap pdfCMap = new PdfCMap(NextObjectId());

            pdfCMap.AddFilter(new FlateFilter());
            pdfCMap.SystemInfo = pdfCidSystemInfo;
            pdfCMap.AddBfRanges(cidFont.CMapEntries);

            // Create a PDF object to represent the CID font
            PdfType0Font pdfFont = new PdfType0Font(
                NextObjectId(), pdfFontID, font.FontName);

            pdfFont.Encoding   = new PdfName(cidFont.Encoding);
            pdfFont.Descendant = pdfCidFont;
            pdfFont.ToUnicode  = pdfCMap;

            // Add all the Pdf objects to the document.  MakeFont will add the actual
            // PdfFont object to the document.
            creator.AddObject(pdfDescriptor);
            creator.AddObject(pdfCidFont);
            creator.AddObject(pdfCMap);
            creator.AddObject(fontFile);

            return(pdfFont);
        }
Beispiel #7
0
        /// <summary>
        /// Draw a string with the given font, inside a fixed rectangle with the given horizontal and vertical alignment inside that rectangle.
        /// </summary>
        /// <param name="text">The string to write.</param>
        /// <param name="font">The font to use to draw.  This must be y <see cref="FontDescriptor"/> object.</param>
        /// <param name="rect">The bounding rectangle to draw the string in.</param>
        /// <param name="hAlign">The horizontal alignment of the string within the bounding rectangle.</param>
        /// <param name="vAlign">The vertical alignment of the string within the bounding rectangle.</param>
        /// <exception cref="ArgumentException" />Thrown if the <see cref="IFontDescriptor" /> paramter is not a <see cref="FontDescriptor" /> object.
        public void DrawString(string text, IFontDescriptor font, UniRectangle rect, HorizontalAlignment hAlign, VerticalAlignment vAlign)
        {
            if (!(font is FontDescriptor ourFont))
            {
                throw new ArgumentException(Resources.Error_FontDescriptorOfWrongSpecificType, nameof(font));
            }
            if (rect is null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            _core.DrawString(text, ourFont.Font, XBrushes.Black, new XRect(rect.Left, rect.Top, rect.Width, rect.Height), GetStringFormat(hAlign, vAlign));
        }
 /// <summary>
 /// Constructor for cell with margins.
 /// </summary>
 /// <param name="content">The cell content.</param>
 /// <param name="font">The font to use to draw the content.</param>
 /// <param name="margins">The cell margins.</param>
 /// <param name="graphicsContext">The graphics context which will be used to draw the cell.</param>
 public PlainTextTableCell(string content, IFontDescriptor font, MarginSet margins, IGraphicsContext graphicsContext)
 {
     Content = content;
     Font    = font;
     if (margins != null)
     {
         MarginLeft   = margins.Left;
         MarginRight  = margins.Right;
         MarginTop    = margins.Top;
         MarginBottom = margins.Bottom;
     }
     MeasureSize(graphicsContext);
 }
Beispiel #9
0
        /// <summary>
        /// Add text to this paragraph.
        /// </summary>
        /// <param name="text">The text to be added.</param>
        /// <param name="font">The font to be used to write the text.</param>
        /// <param name="graphicsContext">The context to be used for metrics.</param>
        public void AddText(string text, IFontDescriptor font, IGraphicsContext graphicsContext)
        {
            var words = Word.MakeWords(text, font, graphicsContext);

            Lines.AddRange(Line.MakeLines(words, MaximumWidth - (Margins.Left + Margins.Right)));
            if (Lines.Any(l => l.OverspillWidth))
            {
                OverspillWidth = true;
            }
            if (Lines.Sum(l => l.ContentHeight) > MaximumHeight)
            {
                OverspillHeight = true;
            }
        }
        public void WordClass_MakeWordsMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfFirstParameterIsNotNullAndSecondParameterIsNull()
        {
            string           testParam0 = _rnd.NextString(_rnd.Next(300));
            IFontDescriptor  testParam1 = null;
            IGraphicsContext testParam2 = new Mock <IGraphicsContext>().Object;

            try
            {
                _ = Word.MakeWords(testParam0, testParam1, testParam2).ToArray();
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("font", ex.ParamName);
            }
        }
Beispiel #11
0
        private static Class40 smethod_4(string fontName, IFontMetric metrics)
        {
            IFontDescriptor descriptor = metrics.Descriptor;
            Class40         class40    = new Class40(fontName);

            class40.Ascent      = metrics.Ascender;
            class40.CapHeight   = metrics.CapHeight;
            class40.Descent     = metrics.Descender;
            class40.Flags       = descriptor.Flags;
            class40.ItalicAngle = descriptor.ItalicAngle;
            class40.StemV       = descriptor.StemV;
            PdfArray pdfArray = new PdfArray();

            pdfArray.AddRange((IEnumerable <int>)descriptor.FontBBox);
            class40.FontBBox = pdfArray;
            return(class40);
        }
Beispiel #12
0
        private PdfFontDescriptor MakeFontDescriptor(string fontName, IFontMetric metrics)
        {
            IFontDescriptor descriptor = metrics.Descriptor;

            PdfFontDescriptor pdfDescriptor = new PdfFontDescriptor(
                fontName, NextObjectId());

            pdfDescriptor.Ascent      = new PdfNumeric(metrics.Ascender);
            pdfDescriptor.CapHeight   = new PdfNumeric(metrics.CapHeight);
            pdfDescriptor.Descent     = new PdfNumeric(metrics.Descender);
            pdfDescriptor.Flags       = new PdfNumeric(descriptor.Flags);
            pdfDescriptor.ItalicAngle = new PdfNumeric(descriptor.ItalicAngle);
            pdfDescriptor.StemV       = new PdfNumeric(descriptor.StemV);

            PdfArray array = new PdfArray();

            array.AddArray(descriptor.FontBBox);
            pdfDescriptor.FontBBox = array;

            return(pdfDescriptor);
        }
Beispiel #13
0
 /// <summary>
 /// Construct a <see cref="Word" /> instance.
 /// </summary>
 /// <param name="content">The textual content of the word.</param>
 /// <param name="font">The font to use for display.</param>
 /// <param name="graphicsContext">The graphics context for providing metrics.</param>
 /// <param name="postWordSpace">The minimum amount of space to add after the word if it is not at the end of a line.</param>
 public Word(string content, IFontDescriptor font, IGraphicsContext graphicsContext, double postWordSpace)
 {
     if (font is null)
     {
         throw new ArgumentNullException(nameof(font));
     }
     Content       = content;
     Font          = font;
     PostWordSpace = postWordSpace;
     if (string.IsNullOrEmpty(Content) || graphicsContext == null)
     {
         ContentWidth   = 0;
         ContentAscent  = 0;
         ContentDescent = 0;
     }
     else
     {
         var measure = graphicsContext.MeasureString(Content, Font);
         ContentWidth   = measure.Width;
         ContentAscent  = font.Ascent;
         ContentDescent = measure.Height - ContentAscent;
     }
 }
Beispiel #14
0
        /// <summary>
        /// Convert a text string into zero or more <see cref="Word" /> instances by splitting it up on white space.
        /// </summary>
        /// <param name="text">The text to use to create the words.</param>
        /// <param name="font">The font to display the text in.</param>
        /// <param name="graphicsContext">The graphics context to use for rendering the words and providing metrics.</param>
        /// <returns>An enumeration of <see cref="Word" /> instances, each consisting of a single word from the input text.</returns>
        public static IEnumerable <Word> MakeWords(string text, IFontDescriptor font, IGraphicsContext graphicsContext)
        {
            if (text is null)
            {
                yield break;
            }
            if (font is null)
            {
                throw new ArgumentNullException(nameof(font));
            }
            double wordSpace = font.GetNormalSpaceWidth(graphicsContext);

            string[] words = text.Split(null);
            Log.Trace("Split text '{0}' into {1} words.", text, words.Length);
            foreach (string word in words)
            {
                if (string.IsNullOrEmpty(word))
                {
                    continue;
                }
                yield return(new Word(word, font, graphicsContext, wordSpace));
            }
        }
 /// <summary>
 /// Draw a string - dummy method
 /// </summary>
 /// <param name="text"></param>
 /// <param name="font"></param>
 /// <param name="rect"></param>
 /// <param name="hAlign"></param>
 /// <param name="vAlign"></param>
 public void DrawString(string text, IFontDescriptor font, UniRectangle rect, HorizontalAlignment hAlign, VerticalAlignment vAlign)
 {
 }
 /// <summary>
 /// Constructor for cell with no margins.
 /// </summary>
 /// <param name="content">The cell content.</param>
 /// <param name="font">The font to use to draw the content.</param>
 /// <param name="graphicsContext">The graphics context which will be used to draw the cell.</param>
 public PlainTextTableCell(string content, IFontDescriptor font, IGraphicsContext graphicsContext) : this(content, font, null, graphicsContext)
 {
 }
        internal static PositionedLine ToPositionedLine(this FootnoteDisplayModel footnote, IGraphicsContext context, IFontDescriptor symbolFont, IFontDescriptor definitionFont)
        {
            Word        symbolWord = new Word(footnote.Symbol, symbolFont, context, 5); // FIXME that very naked-looing "5" should definitely not be hard-coded.
            List <Word> theWords   = new List <Word> {
                symbolWord
            };

            theWords.AddRange(Word.MakeWords(footnote.Definition, definitionFont, context));
            return(new PositionedLine(theWords));
        }
        public static void PopulateSize(this TrainGraphAxisTickInfo tickInfo, IGraphicsContext context, IFontDescriptor font)
        {
            if (tickInfo is null)
            {
                throw new ArgumentNullException(nameof(tickInfo));
            }
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            UniSize measure = context.MeasureString(tickInfo.Label, font);

            tickInfo.Width  = measure.Width;
            tickInfo.Height = measure.Height;
        }
 /// <summary>
 /// Draw a string - dummy method
 /// </summary>
 /// <param name="text"></param>
 /// <param name="font"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void DrawString(string text, IFontDescriptor font, double x, double y)
 {
 }
 /// <summary>
 /// Measure a string - dummy method that returns a very rough approximation.
 /// </summary>
 /// <param name="text">The text to be measured</param>
 /// <param name="font">The font in which the text is to be displayed</param>
 /// <returns></returns>
 public UniSize MeasureString(string text, IFontDescriptor font)
 {
     return(new UniSize((text ?? "").Length * 5, 7.2));
 }