private int GetFontId(FontDescriptor fd)
        {
            var fontId = String.Intern(fd.Id);

            var index = m_registeredFonts.FindIndex(fm => Object.ReferenceEquals(fm.m_id, fontId));
            if (index == -1)
            {
                var fontObject = new Font(fd.FamilyName, fd.Size, fd.Style);
                m_registeredFonts.Add(new FontMetrics
                {
                    m_id = fontId,
                    m_fontObject = fontObject,
                    m_outlineThickness = fd.OutlineThickness,
                    m_spaceWidth = MeasureSpace(fontObject).Width,
                    m_fullWidthSpaceWidth = MeasureFullwidthSpace(fontObject).Width,
                    m_ascentInPixels = CalculateAscentInPixel(fontObject)
                });
                index = m_registeredFonts.Count - 1;
            }

            if (index > 0xffff)
            {
                throw new OverflowException("Number of registered font has grown ridiculously too large.");
            }

            return index;
        }
Esempio n. 2
0
        public static int GetWpfValue(XFontFamily family, XFontStyle style, GWV value)
        {
            FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style);
            XFontMetrics   metrics    = descriptor.FontMetrics;

            switch (value)
            {
            case GWV.GetCellAscent:
                return(metrics.Ascent);

            case GWV.GetCellDescent:
                return(Math.Abs(metrics.Descent));

            case GWV.GetEmHeight:
                //return (int)metrics.CapHeight;
                return(metrics.UnitsPerEm);

            case GWV.GetLineSpacing:
                return(metrics.Ascent + Math.Abs(metrics.Descent) + metrics.Leading);

            default:
                throw new InvalidOperationException("Unknown GWV value.");
                // DELETE
                //case GWV.IsStyleAvailable:
                //  style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic
                //  List<Typeface> s_typefaces = new List<Typeface>(family.wpfFamily.GetTypefaces());
                //  foreach (Typeface typeface in s_typefaces)
                //  {
                //  }
                //  Debugger.Break();
                ////typeface.Style = FontStyles.
            }
        }
Esempio n. 3
0
        private ICidFontProgram ReadDescriptorFile(FontDescriptor descriptor)
        {
            if (descriptor?.FontFile == null)
            {
                return(null);
            }

            var fontFileStream = DirectObjectFinder.Get <StreamToken>(descriptor.FontFile.ObjectKey, pdfScanner);

            if (fontFileStream == null)
            {
                return(null);
            }

            var fontFile = fontFileStream.Decode(filterProvider);

            switch (descriptor.FontFile.FileType)
            {
            case DescriptorFontFile.FontFileType.TrueType:
                var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile));
                return(trueTypeFontParser.Parse(input));

            default:
                throw new NotSupportedException("Currently only TrueType fonts are supported.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the FontDescriptor identified by the specified FontSelector. If no such object
        /// exists, a new FontDescriptor is created and added to the stock.
        /// </summary>
        public static FontDescriptor GetOrCreateDescriptor(string fontFamilyName, XFontStyle style)
        {
            if (string.IsNullOrEmpty(fontFamilyName))
            {
                throw new ArgumentNullException("fontFamilyName");
            }

            //FontSelector1 selector = new FontSelector1(fontFamilyName, style);
            string fontDescriptorKey = FontDescriptor.ComputeKey(fontFamilyName, style);

            try
            {
                Lock.EnterFontFactory();
                FontDescriptor descriptor;
                if (!Singleton._cache.TryGetValue(fontDescriptorKey, out descriptor))
                {
                    XFont font = new XFont(fontFamilyName, 10, style);
                    descriptor = GetOrCreateDescriptorFor(font);
                    if (Singleton._cache.ContainsKey(fontDescriptorKey))
                    {
                        Singleton.GetType();
                    }
                    else
                    {
                        Singleton._cache.Add(fontDescriptorKey, descriptor);
                    }
                }
                return(descriptor);
            }
            finally { Lock.ExitFontFactory(); }
        }
Esempio n. 5
0
        private TrueTypeFont ParseTrueTypeFont(FontDescriptor descriptor)
        {
            if (descriptor?.FontFile == null)
            {
                return(null);
            }

            if (descriptor.FontFile.FileType != DescriptorFontFile.FontFileType.TrueType)
            {
                throw new InvalidFontFormatException(
                          $"Expected a TrueType font in the TrueType font descriptor, instead it was {descriptor.FontFile.FileType}.");
            }

            try
            {
                var fontFileStream = DirectObjectFinder.Get <StreamToken>(descriptor.FontFile.ObjectKey, pdfScanner);

                var fontFile = fontFileStream.Decode(filterProvider);

                var font = trueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));

                return(font);
            }
            catch (Exception ex)
            {
                log.Error("Could not parse the TrueType font.", ex);

                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets a <see cref="SKPaint"/> containing information needed to render text.
        /// </summary>
        /// <remarks>
        /// This modifies and returns the local <see cref="paint"/> instance.
        /// </remarks>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="shaper">The font shaper.</param>
        /// <returns>The paint.</returns>
        private SKPaint GetTextPaint(string fontFamily, double fontSize, double fontWeight, out SKShaper shaper)
        {
            var fontDescriptor = new FontDescriptor(fontFamily, fontWeight);

            if (!this.typefaceCache.TryGetValue(fontDescriptor, out var typeface))
            {
                typeface = SKTypeface.FromFamilyName(fontFamily, new SKFontStyle((int)fontWeight, (int)SKFontStyleWidth.Normal, SKFontStyleSlant.Upright));
                this.typefaceCache.Add(fontDescriptor, typeface);
            }

            if (this.UseTextShaping)
            {
                if (!this.shaperCache.TryGetValue(fontDescriptor, out shaper))
                {
                    shaper = new SKShaper(typeface);
                    this.shaperCache.Add(fontDescriptor, shaper);
                }
            }
            else
            {
                shaper = null;
            }

            this.paint.Typeface     = typeface;
            this.paint.TextSize     = this.Convert(fontSize);
            this.paint.IsAntialias  = true;
            this.paint.Style        = SKPaintStyle.Fill;
            this.paint.HintingLevel = this.RendersToScreen ? SKPaintHinting.Full : SKPaintHinting.NoHinting;
            this.paint.SubpixelText = this.RendersToScreen;
            return(this.paint);
        }
Esempio n. 7
0
        private ICidFontProgram ReadDescriptorFile(FontDescriptor descriptor)
        {
            if (descriptor?.FontFile == null)
            {
                return(null);
            }

            var fontFileStream = DirectObjectFinder.Get <StreamToken>(descriptor.FontFile.ObjectKey, pdfScanner);

            if (fontFileStream == null)
            {
                return(null);
            }

            var fontFile = fontFileStream.Decode(filterProvider);

            switch (descriptor.FontFile.FileType)
            {
            case DescriptorFontFile.FontFileType.TrueType:
                var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile));
                return(trueTypeFontParser.Parse(input));

            case DescriptorFontFile.FontFileType.FromSubtype:
            {
                if (!DirectObjectFinder.TryGet(descriptor.FontFile.ObjectKey, pdfScanner, out StreamToken str))
                {
                    throw new NotSupportedException("Cannot read CID font from subtype.");
                }

                if (!str.StreamDictionary.TryGet(NameToken.Subtype, out NameToken subtypeName))
                {
                    throw new PdfDocumentFormatException($"The font file stream did not contain a subtype entry: {str.StreamDictionary}.");
                }

                if (subtypeName == NameToken.CidFontType0C)
                {
                    var bytes = str.Decode(filterProvider);
                    var font  = compactFontFormatParser.Parse(new CompactFontFormatData(bytes));
                    return(font);
                }

                if (subtypeName == NameToken.Type1C)
                {
                }
                else if (subtypeName == NameToken.OpenType)
                {
                }
                else
                {
                    throw new PdfDocumentFormatException($"Unexpected subtype for CID font: {subtypeName}.");
                }

                throw new NotSupportedException("Cannot read CID font from subtype.");
            }

            default:
                throw new NotSupportedException("Currently only TrueType fonts are supported.");
            }
        }
Esempio n. 8
0
        public Rtf2ColumnLogFormatter()
        {
            _doc = new RtfDocument(PaperSize.A3,
                                   PaperOrientation.Landscape,
                                   Lcid.English);

            _consolas = _doc.createFont("Consolas");
        }
        public void FontDescriptorClass_GetNormalSpaceWidthMethod_ThrowsArgumentNullException_IfParameterIsNull()
        {
            IGraphicsContext testParam0 = null;
            FontDescriptor   testObject = new FontDescriptor("Times", 10);

            testObject.GetNormalSpaceWidth(testParam0);

            Assert.Fail();
        }
Esempio n. 10
0
		internal void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
		{
			ComboBox comboBox = (ComboBox)sender;
			if (e.Index >= 0) {
				FontDescriptor fontDescriptor = (FontDescriptor)comboBox.Items[e.Index];
				SizeF size = e.Graphics.MeasureString(fontDescriptor.Name, comboBox.Font);
				e.ItemWidth  = (int)size.Width;
				e.ItemHeight = (int)comboBox.Font.Height;
			}
		}
Esempio n. 11
0
 public Type1FontSimple(NameToken name, int firstChar, int lastChar, decimal[] widths, FontDescriptor fontDescriptor, Encoding encoding, CMap toUnicodeCMap)
 {
     this.firstChar      = firstChar;
     this.lastChar       = lastChar;
     this.widths         = widths;
     this.fontDescriptor = fontDescriptor;
     this.encoding       = encoding;
     this.toUnicodeCMap  = new ToUnicodeCMap(toUnicodeCMap);
     Name = name;
 }
 public FormatOptions(FontDescriptor font, FontDescriptor ansiFont)
 {
     Font = font;
     AnsiFont = ansiFont;
     Alignment = TextRenderer.Alignment.LeftTop;
     CharSpacing = 0;
     LineSpacing = 0;
     TabSpaces = 4;
     DisableRTF = false;
 }
Esempio n. 13
0
 public FontDescriptorView(FontDescriptor font)
 {
     IsDefault       = font.IsDefault;
     FontFamily      = font.FontFamily;
     FontWeight      = font.FontWeight;
     FontStyle       = font.FontStyle;
     FontStretch     = font.FontStretch;
     TextDecorations = font.TextDecorations;
     FontSize        = font.FontSize;
 }
Esempio n. 14
0
            internal void TestConvertFrom(CultureInfo culture, string input, string expectedName, float expectedSize, GraphicsUnit expectedUnits, FontStyle expectedFontStyle)
            {
                Thread.CurrentThread.CurrentCulture = culture;

                FontDescriptor font = FontConverter.ConvertFrom(input) !;

                Assert.Equal(expectedName, font.Name);
                Assert.Equal(expectedSize, font.Size);
                Assert.Equal(expectedUnits, font.Unit);
                Assert.Equal(expectedFontStyle, font.Style);
            }
Esempio n. 15
0
            private void ProcessValueInfo(DomNode valInfo, string propName,
                                          List <System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type   type     = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {
                    TypeConverter converter;
                    object        editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                                                                              , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {
                                int    k         = 1;
                                string paramName = propName + " : Arg_";
                                foreach (DomNode vInfoChild in vInfoChildList)
                                {
                                    string name = paramName + k;
                                    ProcessValueInfo(vInfoChild, name, descriptors);
                                    k++;
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
        public void FontDescriptorClass_GetNormalSpaceWidthMethod_ReturnsWidthPropertyOfObjectReturnedByMeasureStringMethodOfParameter_IfParameterIsNotNull()
        {
            Mock <IGraphicsContext> testParam0Wrapper = new Mock <IGraphicsContext>();
            double expectedResult = _rnd.NextDouble() * 1000;

            testParam0Wrapper.Setup(m => m.MeasureString(It.IsAny <string>(), It.IsAny <IFontDescriptor>())).Returns(new UniSize(expectedResult, _rnd.NextDouble() * 1000));
            FontDescriptor testObject = new FontDescriptor("Times", 10);

            double testOutput = testObject.GetNormalSpaceWidth(testParam0Wrapper.Object);

            Assert.AreEqual(expectedResult, testOutput);
        }
        public void FontDescriptorClass_GetNormalSpaceWidthMethod_CallsMeasureStringMethodOfParameterWithSecondParameterEqualToItself_IfParameterIsNotNull()
        {
            Mock <IGraphicsContext> testParam0Wrapper = new Mock <IGraphicsContext>();
            double expectedResult = _rnd.NextDouble() * 1000;

            testParam0Wrapper.Setup(m => m.MeasureString(It.IsAny <string>(), It.IsAny <IFontDescriptor>())).Returns(new UniSize(expectedResult, _rnd.NextDouble() * 1000));
            FontDescriptor testObject = new FontDescriptor("Times", 10);

            testObject.GetNormalSpaceWidth(testParam0Wrapper.Object);

            testParam0Wrapper.Verify(m => m.MeasureString(It.IsAny <string>(), testObject), Times.Once());
        }
Esempio n. 18
0
            public override bool Equals(object obj)
            {
                bool result = object.ReferenceEquals(this, obj);

                if (!result)
                {
                    FontDescriptor other = obj as FontDescriptor;
                    result = EmSize == other.EmSize && FontStyle == other.FontStyle && GraphicsUnit == other.GraphicsUnit && FamilyName == other.FamilyName;
                }

                return(result);
            }
Esempio n. 19
0
        private void TypeParagraph(int fontsize, Align align, string text)
        {
            FontDescriptor times = doc.createFont("Times New Roman");
            RtfCharFormat  fmt;
            RtfParagraph   par;

            par           = doc.addParagraph();
            par.Alignment = align;
            fmt           = par.addCharFormat();
            fmt.Font      = times;
            fmt.FontSize  = fontsize;
            par.setText(text);
        }
Esempio n. 20
0
		public Font GetSelectedFont()
		{
			if (!fontListComboBox.Enabled)
				return null;
			int fontSize = 10;
			try {
				fontSize = Math.Max(6, Int32.Parse(fontSizeComboBox.Text));
			} catch (Exception) {}
			
			FontDescriptor fontDescriptor = (FontDescriptor)fontListComboBox.Items[fontListComboBox.SelectedIndex];
			
			return new Font(fontDescriptor.Name,
			                fontSize);
		}
Esempio n. 21
0
        private static CosName GetName(PdfDictionary dictionary, FontDescriptor descriptor)
        {
            if (dictionary.TryGetName(CosName.BASE_FONT, out CosName name))
            {
                return(name);
            }

            if (descriptor.FontName != null)
            {
                return(descriptor.FontName);
            }

            throw new InvalidFontFormatException($"Could not find a name for this TrueType font {dictionary}.");
        }
Esempio n. 22
0
        /// <summary>
        /// Returns the font requested.
        /// </summary>
        /// <param name="familyName"></param>
        /// <param name="emSize"></param>
        /// <param name="fontStyle"></param>
        /// <param name="graphicsUnit"></param>
        /// <returns></returns>
        public Font BuildFont(string familyName, float emSize, FontStyle fontStyle, GraphicsUnit graphicsUnit)
        {
            var descriptor = new FontDescriptor(familyName, emSize, fontStyle, graphicsUnit);
            Font result;

            lock(_SyncLock) {
                if(!_Fonts.TryGetValue(descriptor, out result)) {
                    result = new Font(familyName, emSize, fontStyle, graphicsUnit);
                    _Fonts.Add(descriptor, result);
                }
            }

            return result;
        }
Esempio n. 23
0
        /// <summary>
        /// Determines whether the style is available as a glyph type face in the specified font family, i.e. the specified style is not simulated.
        /// </summary>
        public static bool IsStyleAvailable(XFontFamily family, XFontStyle style)
        {
#if !SILVERLIGHT
            // TODOWPF: check for correctness
            FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style);
            XFontMetrics   metrics    = descriptor.FontMetrics;

            style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic
            List <Typeface> typefaces = new List <Typeface>(family.wpfFamily.GetTypefaces());
            foreach (Typeface typeface in typefaces)
            {
                bool          available = false;
                GlyphTypeface glyphTypeface;
                if (typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
#if DEBUG
                    glyphTypeface.GetType();
#endif
                    available = true;
                }

#if DEBUG_ //
                int weightClass = typeface.Weight.ToOpenTypeWeight();
                switch (style)
                {
                case XFontStyle.Regular:
                    //if (typeface.TryGetGlyphTypeface(.Style == FontStyles.Normal && typeface.Weight== FontWeights.Normal.)
                    break;

                case XFontStyle.Bold:
                    break;

                case XFontStyle.Italic:
                    break;

                case XFontStyle.BoldItalic:
                    break;
                }
#endif
                if (available)
                {
                    return(true);
                }
            }
            return(false);
#else
            return(true); // AGHACK
#endif
        }
Esempio n. 24
0
        public ICidFont Generate(DictionaryToken dictionary, bool isLenientParsing)
        {
            var type = dictionary.GetNameOrDefault(NameToken.Type);

            if (!NameToken.Font.Equals(type))
            {
                throw new InvalidFontFormatException($"Expected \'Font\' dictionary but found \'{type}\'");
            }

            var widths = ReadWidths(dictionary);

            var defaultWidth = default(double?);

            if (dictionary.TryGet(NameToken.Dw, pdfScanner, out NumericToken defaultWidthToken))
            {
                defaultWidth = defaultWidthToken.Double;
            }

            var verticalWritingMetrics = ReadVerticalDisplacements(dictionary);

            FontDescriptor descriptor = null;

            if (TryGetFontDescriptor(dictionary, out var descriptorDictionary))
            {
                descriptor = descriptorFactory.Generate(descriptorDictionary, pdfScanner, isLenientParsing);
            }

            var fontProgram = ReadDescriptorFile(descriptor);

            var baseFont = dictionary.GetNameOrDefault(NameToken.BaseFont);

            var systemInfo = GetSystemInfo(dictionary);

            var subType = dictionary.GetNameOrDefault(NameToken.Subtype);

            if (NameToken.CidFontType0.Equals(subType))
            {
                return(new Type0CidFont(fontProgram, type, subType, baseFont, systemInfo, descriptor, verticalWritingMetrics, widths, defaultWidth));
            }

            if (NameToken.CidFontType2.Equals(subType))
            {
                var cidToGid = GetCharacterIdentifierToGlyphIndexMap(dictionary, isLenientParsing);

                return(new Type2CidFont(type, subType, baseFont, systemInfo, descriptor, fontProgram, verticalWritingMetrics, widths, defaultWidth, cidToGid));
            }

            return(null);
        }
        public void FontDescriptorClass_GetNormalSpaceWidthMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            IGraphicsContext testParam0 = null;
            FontDescriptor   testObject = new FontDescriptor("Times", 10);

            try
            {
                testObject.GetNormalSpaceWidth(testParam0);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("graphicsContext", ex.ParamName);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Returns the font requested.
        /// </summary>
        /// <param name="familyName"></param>
        /// <param name="emSize"></param>
        /// <param name="fontStyle"></param>
        /// <param name="graphicsUnit"></param>
        /// <returns></returns>
        public Font BuildFont(string familyName, float emSize, FontStyle fontStyle, GraphicsUnit graphicsUnit)
        {
            var  descriptor = new FontDescriptor(familyName, emSize, fontStyle, graphicsUnit);
            Font result;

            lock (_SyncLock) {
                if (!_Fonts.TryGetValue(descriptor, out result))
                {
                    result = new Font(familyName, emSize, fontStyle, graphicsUnit);
                    _Fonts.Add(descriptor, result);
                }
            }

            return(result);
        }
Esempio n. 27
0
        public TrueTypeSimpleFont(CosName name, int firstCharacterCode, int lastCharacterCode, decimal[] widths,
                                  FontDescriptor descriptor,
                                  [CanBeNull] CMap toUnicodeCMap,
                                  [CanBeNull] Encoding encoding)
        {
            this.firstCharacterCode = firstCharacterCode;
            this.lastCharacterCode  = lastCharacterCode;
            this.widths             = widths;
            this.descriptor         = descriptor;
            this.encoding           = encoding;

            Name       = name;
            IsVertical = false;
            ToUnicode  = new ToUnicodeCMap(toUnicodeCMap);
        }
Esempio n. 28
0
        public Type0CidFont(ICidFontProgram fontProgram, NameToken type, NameToken subType, NameToken baseFont,
                            CharacterIdentifierSystemInfo systemInfo,
                            FontDescriptor descriptor, IReadOnlyDictionary <int, decimal> widths)
        {
            this.fontProgram = fontProgram;
            Type             = type;
            SubType          = subType;
            BaseFont         = baseFont;
            SystemInfo       = systemInfo;
            var scale = 1 / (decimal)(fontProgram?.GetFontMatrixMultiplier() ?? 1000);

            FontMatrix = TransformationMatrix.FromValues(scale, 0, 0, scale, 0, 0);
            Descriptor = descriptor;
            Widths     = widths;
        }
Esempio n. 29
0
        private static bool TryGetNamedEncoding(FontDescriptor descriptor, NameToken encodingName, out Encoding encoding)
        {
            encoding = null;
            // Symbolic fonts default to standard encoding.
            if (descriptor?.Flags.HasFlag(FontDescriptorFlags.Symbolic) == true)
            {
                encoding = StandardEncoding.Instance;
            }

            if (!Encoding.TryGetNamedEncoding(encodingName, out encoding))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 30
0
        protected void TypeCellParagraph(RtfTableCell cell, int fontsize, Align align, string text)
        {
            if (doc != null)
            {
                FontDescriptor times = doc.createFont("Times New Roman");
                RtfCharFormat  fmt;
                RtfParagraph   par;

                par           = cell.addParagraph();
                par.Alignment = align;
                fmt           = par.addCharFormat();
                fmt.Font      = times;
                fmt.FontSize  = fontsize;
                par.setText(text);
            }
        }
        public Font GetSelectedFont()
        {
            if (!fontListComboBox.Enabled)
            {
                return(null);
            }
            float fontSize = 10f;

            try {
                fontSize = Math.Max(6, Single.Parse(fontSizeComboBox.Text));
            } catch (Exception) {}

            FontDescriptor fontDescriptor = (FontDescriptor)fontListComboBox.Items[fontListComboBox.SelectedIndex];

            return(new Font(fontDescriptor.Name,
                            fontSize));
        }
Esempio n. 32
0
        private Type1Font ParseType1Font(FontDescriptor descriptor, bool isLenientParsing)
        {
            if (descriptor?.FontFile == null)
            {
                return(null);
            }

            if (descriptor.FontFile.ObjectKey.Data.ObjectNumber == 0)
            {
                return(null);
            }

            try
            {
                if (!(pdfScanner.Get(descriptor.FontFile.ObjectKey.Data).Data is StreamToken stream))
                {
                    return(null);
                }

                var bytes = stream.Decode(filterProvider);

                // We have a Compact Font Format font rather than an Adobe Type 1 Font.
                if (stream.StreamDictionary.TryGet(NameToken.Subtype, out NameToken subTypeName) &&
                    NameToken.Type1C.Equals(subTypeName))
                {
                    compactFontFormatParser.Parse(new CompactFontFormatData(bytes));
                    return(null);
                }

                var length1 = stream.StreamDictionary.Get <NumericToken>(NameToken.Length1, pdfScanner);
                var length2 = stream.StreamDictionary.Get <NumericToken>(NameToken.Length2, pdfScanner);

                var font = type1FontParser.Parse(new ByteArrayInputBytes(bytes), length1.Int, length2.Int);

                return(font);
            }
            catch
            {
                if (!isLenientParsing)
                {
                    throw;
                }
            }

            return(null);
        }
Esempio n. 33
0
        private static Encoding GetNamedEncoding(FontDescriptor descriptor, NameToken encodingName)
        {
            Encoding encoding;

            // Symbolic fonts default to standard encoding.
            if (descriptor?.Flags.HasFlag(FontFlags.Symbolic) == true)
            {
                encoding = StandardEncoding.Instance;
            }

            if (!Encoding.TryGetNamedEncoding(encodingName, out encoding))
            {
                // TODO: PDFBox would not throw here.
                throw new InvalidFontFormatException($"Unrecognised encoding name: {encodingName}");
            }

            return(encoding);
        }
        public HtmlFontDescriptors(int normalFontHeight = 0)
        {
            Normal = HtmlHandler.GenerateBasicFontDescriptor();
            Normal.Height = (short)normalFontHeight;
            #region Header
            H1 = Normal;
            H1.Height += 5;

            H2 = H1;
            H1.Height -= 2;

            H3 = H2;
            H1.Height -= 2;

            H4 = H3;
            H5 = H4;
            H6 = H5;
            #endregion
        }
Esempio n. 35
0
            private void ProcessValueInfo(DomNode valInfo, string propName,
                List<System.ComponentModel.PropertyDescriptor> descriptors)
            {
                string typeName = (string)valInfo.GetAttribute(SkinSchema.valueInfoType.typeAttribute);
                Type type = SkinUtil.GetType(typeName);


                if (type == typeof(Font))
                {
                    FontDescriptor descr
                        = new FontDescriptor(valInfo, propName, null, null, null, null);
                    descriptors.Add(descr);
                }
                else
                {

                    TypeConverter converter;
                    object editor;
                    GetEditorAndConverter(type, out editor, out converter);
                    if (editor != null)
                    {
                        var descr = new SkinSetterAttributePropertyDescriptor(valInfo
                            , propName, SkinSchema.valueInfoType.valueAttribute, null, null, false, editor, converter);
                        descriptors.Add(descr);
                    }
                    else
                    {
                        DomNode ctorParams = valInfo.GetChild(SkinSchema.valueInfoType.constructorParamsChild);
                        if (ctorParams != null)
                        {
                            var vInfoChildList = ctorParams.GetChildList(SkinSchema.constructorParamsType.valueInfoChild);
                            if (vInfoChildList.Count == 1)
                            {
                                ProcessValueInfo(vInfoChildList[0], propName, descriptors);
                            }
                            else
                            {

                                // special handling for SyntaxEditorControl
                                if (typeName == "Sce.Atf.Controls.SyntaxEditorControl.TextHighlightStyle")
                                {
                                    string argName =
                                    (string)vInfoChildList[0].GetAttribute(SkinSchema.valueInfoType.valueAttribute);

                                    string name = propName + "->" + argName;
                                    ProcessValueInfo(vInfoChildList[1], name, descriptors);
                                }
                                else
                                {
                                    int k = 1;
                                    string paramName = propName + " : Arg_";
                                    foreach (DomNode vInfoChild in vInfoChildList)
                                    {
                                        string name = paramName + k;
                                        ProcessValueInfo(vInfoChild, name, descriptors);
                                        k++;
                                    }
                                }
                            }
                        }

                        foreach (DomNode setterChild in valInfo.GetChildList(SkinSchema.valueInfoType.setterChild))
                        {
                            ProcessSetterType(setterChild, propName, descriptors);
                        }
                    }
                }
            }
 public FormatOptions(FontDescriptor font) : this(font, font)
 { }
Esempio n. 37
0
        private bool adjustmentFont(Bitmap image, FontDescriptor zipos, Encoding ec, byte ascii)
        {
            Graphics graphics = null;
            try
            {
                bool flag = true;
                int num = 0;
                byte[] bytes = new byte[] { ascii };
                string s = ec.GetString(bytes, 0, 1);
                FontDescriptor fontDesc = new FontDescriptor();
                fontDesc = zipos;
                int width = image.Width;
                int height = image.Height;

                if (width != height / 2)
                    width = height / 2;

                Graphics.FromImage(image).Clear(Color.FromArgb(0, 0, 0));
                Bitmap bmi = new Bitmap(width * 3, height * 2);
                using (graphics = Graphics.FromImage(bmi))
                {
                    if (s == "w")
                        s = "w";

                    if (s != "" && s != " ")
                    {
                        while (flag)
                        {
                            int num7;
                            Graphics graphics2;
                            int num4 = 0;
                            fontDesc.Ypi--;

                            while (num4 == 0)
                            {
                                fontDesc.Ypi++;
                                Font font = new Font(fontDesc.FontName, fontDesc.FontSize, fontDesc.FontStyle);
                                graphics.Clear(Color.FromArgb(0, 0, 0));
                                graphics.DrawString(s, font, Brushes.Red, (PointF)new Point(0, fontDesc.Ypi));
                                num4 = GdiFont.GetYFree(bmi);
                            }
                            Bitmap bitmap2 = new Bitmap(bmi.Width, height);
                            int height2 = bmi.Height - GdiFont.GetY2Free(bmi);
                            if (height2 > height)
                                Graphics.FromImage(bitmap2).DrawImage(
                                                            bmi,
                                                            new Rectangle(0, 0, bitmap2.Width, bitmap2.Height),
                                                            new Rectangle(0, 0, bitmap2.Width, height2),
                                                            GraphicsUnit.Pixel
                                                            );
                            else
                                Graphics.FromImage(bitmap2).DrawImage(
                                                            bmi,
                                                            new Rectangle(0, 0, bitmap2.Width, bitmap2.Height),
                                                            new Rectangle(0, 0, bitmap2.Width, bitmap2.Height),
                                                            GraphicsUnit.Pixel
                                                            );

                            int bmwidth = GdiFont.GetImageWidth(bitmap2);
                            if ((width > 24 && bmwidth < width) || (width <= 24 && bmwidth <= width + 1))
                            {
                                num4 = GdiFont.GetXFree(bitmap2);
                                num7 = (width - bmwidth) / 2;
                                graphics2 = Graphics.FromImage(image);
                                if (num > 0)
                                {
                                    int num8 = GdiFont.GetY2Free(bitmap2);
                                    Graphics.FromImage(image).DrawImage(
                                                                bitmap2,
                                                                new Rectangle(0, 0, width, height),
                                                                new Rectangle(num4 - num7, num - num8, width, height),
                                                                GraphicsUnit.Pixel
                                                                );
                                }
                                else
                                    Graphics.FromImage(image).DrawImage(
                                                                bitmap2,
                                                                new Rectangle(0, 0, width, height),
                                                                new Rectangle(num4 - num7, 0, width, height),
                                                                GraphicsUnit.Pixel
                                                                );
                                graphics2.Dispose();
                                flag = false;
                            }
                            else if (cbCompensation.SelectedIndex == 3)
                            {
                                if (num == 0)
                                    num = GdiFont.GetY2Free(bitmap2);
                                fontDesc.FontSize -= 0.5f;
                                flag = true;
                            }
                            else
                            {
                                num7 = GdiFont.GetXFree(bitmap2);
                                using (graphics2 = Graphics.FromImage(image))
                                {
                                    graphics2.InterpolationMode = m_settings;
                                    if (width > 24)
                                        graphics2.DrawImage(
                                                    bitmap2,
                                                    new Rectangle(1, 0, width - 2, height),
                                                    new Rectangle(num7, 0, bmwidth, height),
                                                    GraphicsUnit.Pixel
                                                    );
                                    else
                                        graphics2.DrawImage(
                                                    bitmap2,
                                                    new Rectangle(0, 0, width, height),
                                                    new Rectangle(num7, 0, bmwidth, height),
                                                    GraphicsUnit.Pixel
                                                    );
                                    if (s == "X")
                                        s = "X";
                                }
                                flag = false;
                            }
                        }
                    }
                    pictureBoxL.Image = image;
                    Application.DoEvents();
                }
                return true;
            }
            catch (Exception ex)
            {
                graphics.Dispose();
                MessageBox.Show(ex.Message);
            }
            return false;
        }
 /// <summary>
 /// Generates the basic font descriptor.
 /// Set this as property 'FontDescriptor'
 /// </summary>
 /// <returns></returns>
 public static FontDescriptor GenerateBasicFontDescriptor()
 {
     FontDescriptor basicFontDescriptor = new FontDescriptor();
     return basicFontDescriptor;
 }