コード例 #1
0
        /// <summary>
        /// Adds a <c>defRPr</c> node (Default Text Run Properties) to the node of type <c>pPr</c> (Text Paragraph Properties) specified. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="node"><c>pPr</c> node (Text Paragraph Properties).</param>
        /// <param name="model">Font from model.</param>
        /// <remarks>
        /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_defRPr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_defRPr-1.html</a>
        /// </remarks>
        private static void AddDefaultTextRunPropertiesNode(this XmlNode node, FontModel model)
        {
            var sizeAttr = ChartXmlHelper.CreateAttribute("sz");

            sizeAttr.Value = (model.Size * 100).ToString(CultureInfo.InvariantCulture);

            var boldAttr = ChartXmlHelper.CreateAttribute("b");

            boldAttr.Value = model.Bold == YesNo.Yes ? "1" : "0";

            var italicAttr = ChartXmlHelper.CreateAttribute("i");

            italicAttr.Value = model.Italic == YesNo.Yes ? "1" : "0";

            var underlineAttr = ChartXmlHelper.CreateAttribute("u");

            underlineAttr.Value = model.Underline == YesNo.Yes ? "sng" : "none";

            var defaultTextRunPropertiesNode = ChartXmlHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "defRPr");

            defaultTextRunPropertiesNode.Attributes.Append(boldAttr);
            defaultTextRunPropertiesNode.Attributes.Append(sizeAttr);
            defaultTextRunPropertiesNode.Attributes.Append(italicAttr);
            defaultTextRunPropertiesNode.Attributes.Append(underlineAttr);

            defaultTextRunPropertiesNode.AddSolidFillNode(model.GetColor());
            defaultTextRunPropertiesNode.AddLatinFontNode(model.Name);
            defaultTextRunPropertiesNode.AddEastAsianFontNode(model.Name);
            defaultTextRunPropertiesNode.AddComplexScriptFontNode(model.Name);
        }
コード例 #2
0
        /// <summary>
        /// Adds a <c>p</c> node (Text Paragraphs) to the node of type <c>txPr</c> (Text properties) specified. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="textPropertiesNode"><c>txPr</c> node (Text properties).</param>
        /// <param name="model">Font from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <remarks>
        /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_p-1.html">http://www.schemacentral.com/sc/ooxml/e-a_p-1.html</a>
        /// </remarks>
        private static void AddTextParagraphsNode(this XmlNode textPropertiesNode, FontModel model, IXmlHelper documentHelper)
        {
            var textParagraphsNode = documentHelper.CreateOrDefaultAndAppendElementToNode(textPropertiesNode, "a", "p");

            textParagraphsNode.AddTextParagraphPropertiesNode(model, documentHelper);
            textParagraphsNode.AddEndParagraphRunPropertiesNode(documentHelper);
        }
コード例 #3
0
ファイル: PdfHelper.cs プロジェクト: lanicon/iExportEngine
        /// <summary>
        /// Creates a new font from model.
        /// </summary>
        /// <param name="font">Font to create.</param>
        /// <returns>
        /// A new <see cref="T:iTextSharp.text.Font" /> that contains specified font from model.
        /// </returns>
        public static Font CreateFont(FontModel font)
        {
            if (font == null)
            {
                font = FontModel.Default;
            }

            var registeredFonts = FontFactory.RegisteredFonts.Count;

            if (registeredFonts <= 14)
            {
                FontFactory.RegisterDirectories();
            }

            var style = Font.NORMAL;

            if (font.Italic == YesNo.Yes)
            {
                style = Font.ITALIC;
            }

            if (font.Bold == YesNo.Yes)
            {
                style = style | Font.BOLD;
            }

            if (font.Underline == YesNo.Yes)
            {
                style = style | Font.UNDERLINE;
            }

            return(FontFactory.GetFont(font.Name, font.Size, style, new BaseColor(font.GetColor())));
        }
コード例 #4
0
        public static GlyphPath Load(uint gid, FontModel fontModel, byte[] fontSource)
        {
            var cff = new CffCharString();

            if (fontModel.IsCidFont)
            {
                var fdIndex = fontModel.TopDict.FDSelect[gid];
                var fdDict  = fontModel.TopDict.FDArray[fdIndex];
                cff._lsubrs       = fdDict.Subrs;
                cff._lsubrsBias   = cff._lsubrs == null ? 0 : CompactFontFormatTable.GetSubrBias(cff._lsubrs.Length);
                cff._width        = fdDict.DefaultWidthX;
                cff._normalWidthX = fdDict.NormalWidthX;
            }
            else
            {
                cff._lsubrs       = fontModel.TopDict.Subrs;
                cff._lsubrsBias   = cff._lsubrs == null ? 0 : CompactFontFormatTable.GetSubrBias(cff._lsubrs.Length);
                cff._width        = fontModel.TopDict.DefaultWidthX;
                cff._normalWidthX = fontModel.TopDict.NormalWidthX;
            }

            cff._gsubrs = fontModel.GSubrs;

            if (cff._gsubrs != null)
            {
                cff._gsubrsBias = CompactFontFormatTable.GetSubrBias(cff._gsubrs.Length);
            }

            var seg = fontModel.GetCharString(gid);

            cff.Load(seg, fontSource);
            fontModel._glyphs[gid] = new GlyphInfo((ushort)cff._width, fontModel._glyphs[gid].LeftSideBearing);

            return(cff._path);
        }
コード例 #5
0
 private void StartAgain()
 {
     FontModelProp   = new FontModel();
     GuessFontFamily = string.Empty;
     GuessFontSize   = string.Empty;
     GuessFontStyle  = string.Empty;
     GuessForeground = string.Empty;
 }
コード例 #6
0
ファイル: CutPic.aspx.cs プロジェクト: zoomlacms/web040
        public System.Drawing.Image AddFontWater(string vpath)
        {
            //string json = "{text:\"水印文字\",family: \"Arial\", size: \"18pt\", weight: \"bold\", style: \"normal\", decoration: \"line-through\",color:\"rgb(255, 51, 153)\", background: \"rgb(204,153,102)\" }";
            string    json  = Request.Form["fontmodel"];
            FontModel model = JsonConvert.DeserializeObject <FontModel>(json);

            return(ImageDealLib.ConverFontToImg(vpath, model));
        }
コード例 #7
0
        /// <summary>
        /// Creates a new font from model.
        /// </summary>
        /// <param name="font">Font to create.</param>
        /// <returns>
        /// A new <see cref="Font"/> that contains specified font from model.
        /// </returns>
        public static Font CreateFont(FontModel font)
        {
            Logger.Instance.Debug("");
            Logger.Instance.Debug(" Assembly: iTin.Utilities.Pdf, Namespace: iTin.Utilities.Pdf.Helpers, Class: PdfHelper");
            Logger.Instance.Debug($" Creates a new font from model");
            Logger.Instance.Debug($" > Signature: ({typeof(Font)}) CreateFont({typeof(FontModel)})");
            Logger.Instance.Debug($"   > font: {font}");

            if (font == null)
            {
                font = FontModel.DefaultFont;
            }

            int registeredFonts = FontFactory.RegisteredFonts.Count;

            if (registeredFonts <= 14)
            {
                FontFactory.RegisterDirectories();
            }

            int style = Font.NORMAL;

            if (font.Italic.AsBoolean())
            {
                style = Font.ITALIC;
            }

            if (font.Bold.AsBoolean())
            {
                style |= Font.BOLD;
            }

            if (font.Underline.AsBoolean())
            {
                style |= Font.UNDERLINE;
            }

            Font validFont;
            var  isFontRegistered = FontFactory.IsRegistered(font.Name);

            if (isFontRegistered)
            {
                validFont = FontFactory.GetFont(
                    font.Name,
                    BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED,
                    font.Size,
                    style,
                    new BaseColor(font.GetColor()));
            }
            else
            {
                var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, FontFactory.DefaultEncoding, BaseFont.EMBEDDED);
                validFont = new Font(baseFont, font.Size, style, new BaseColor(font.GetColor()));
            }

            return(validFont);
        }
コード例 #8
0
ファイル: AngelCodeFont.cs プロジェクト: blockspacer/FrankE
        public static void LoadFontFile(AtlasModel atlasmodel)
        {
            // example?
            //  https://github.com/cyotek/Cyotek.Drawing.BitmapFont

            BitmapFont _font = new BitmapFont();

            _font.Load(atlasmodel.AngelcodeFontFile);

            FontModel newfont = new FontModel();

            newfont.Id          = (ushort)_font.FontSize;       // (ushort)fontSettings.FontSize,
            newfont.size        = _font.FontSize;               // fontSettings.FontSize,
            newfont.lineheight  = (int)(_font.LineHeight);      // glyphHeight, // 22,
            newfont.spacelength = (int)(_font.FontSize * 0.6f); //FIXME ----------  (int)(glyphWidth * 0.6f), //todo ?
            newfont.baseline    = _font.BaseHeight;             // 0,
                                                                // newfont.kerning = _font.kern - 0.5f,
                                                                //  newfont.monowidth = _font.mono fontSettings.FontSize + 1,
            newfont.letterspacing = 0;

            //  newfont.rangeFrom = _font.Characters[0];
            //  newfont.rangeTo = _font.Characters[_font.Characters.Length - 1];

            foreach (var character in _font.Characters)
            {
                newfont.SetGlyph(character.Key.ToString(), new Glyph()
                {
                    advance  = character.Value.XAdvance
                    , height = character.Value.Bounds.Height
                    , width  = character.Value.Bounds.Width
                    , X      = character.Value.Bounds.X
                    , Y      = character.Value.Bounds.Y
                });
                newfont.SetVerticalOffset(character.Key.ToString(), character.Value.Offset.Y);
                newfont.offset = new FontOffset()
                {
                    x = character.Value.Offset.X,
                    y = character.Value.Offset.Y
                };
                //  newfont.spacelength = character.Value.
            }

            foreach (var kerning in _font.Kernings)
            {
                //if(kerning.Key.FirstCharacter != 'o' && kerning.Key.FirstCharacter != 'v')
                //{
                //    continue;
                //}
                newfont.SetKerning(kerning.Key.FirstCharacter.ToString(), new Kerning()
                {
                    KerningValue = kerning.Value, RightGlyphID = kerning.Key.SecondCharacter
                });
            }


            atlasmodel.Fonts.Add(newfont);
        }
コード例 #9
0
        public static void LoadFont(GorillaModel gorilla, StreamReader sr, string line)
        {
            //// TODO load Angelcode's BmFont tool.

            FontModel font = new FontModel();

            //font.size = convertToInt(line.Replace("[Font.", "").Replace("]", ""));
            //font.Id = convertToUShort(line.Replace("[Font.", "").Replace("]", ""));
            //font.Name = line;
            while (!String.IsNullOrEmpty(line = sr.ReadLine()))
            {
                if (line.StartsWith("info"))
                {
                    string[] info = line.Split(' ');
                    font.size = convertToInt(info[2].Split('=')[1]);
                    font.Id   = convertToUShort(info[2].Split('=')[1]);
                    // font.padding = convertToUShort(info[2].Split('=')[1]);
                    // font.spacing = convertToUShort(info[2].Split('=')[1]);
                }
                else if (line.StartsWith("common"))
                {
                    string[] info = line.Split(' ');
                    font.lineheight = convertToInt(info[1].Split('=')[1]);
                }


                //else if (line.StartsWith("glyph"))
                //{
                //    String[] glyphString = line.Split(' ');
                //    font.SetGlyph(convertToUInt(glyphString[0].Split('_')[1]), new Glyph() { X = convertToInt(glyphString[1]), Y = convertToInt(glyphString[2]), width = convertToInt(glyphString[3]), height = convertToInt(glyphString[4]), advance = convertToInt(glyphString[5]) }, "");
                //}
                //else if (line.Contains("verticaloffset_"))
                //{
                //    String[] verticaloffset_String = line.Split(' ');
                //    font.SetVerticalOffset(convertToUInt(verticaloffset_String[0].Split('_')[1]), convertToInt(verticaloffset_String[1]));
                //}
                //else if (line.Contains("kerning_"))
                //{
                //    String[] kerning_String = line.Split(' ');
                //    font.SetKerning(convertToUInt(kerning_String[0].Split('_')[1]), new Kerning() { RightGlyphID = convertToUInt(kerning_String[1]), KerningValue = convertToInt(kerning_String[2]) });
                //}
                //glyph_33 0 0 8 21
                //verticaloffset_33 -11
                //            glyph_121 101 270 25 37
                //verticaloffset_121 -18
                //kerning_121 65 1
                //kerning_121 76 1
                //kerning_121 84 2
                //kerning_121 86 1
            }

            gorilla.Fonts.Add(font);
            gorilla.Items.Add(font);
        }
コード例 #10
0
        public MainPage()
        {
            this.InitializeComponent();

            PickSVGFolderButton.Click += new RoutedEventHandler(PickFolderButton_Click);
            PickAFileButton.Click     += new RoutedEventHandler(SelectFontFile_Click);
            SaveFileButton.Click      += new RoutedEventHandler(SaveFileButton_Click);

            svgFiles         = new ObservableCollection <SvgFileItem>();
            fontFile         = new FontModel();
            selectedSvgItems = new List <object>();
        }
コード例 #11
0
        /// <summary>
        /// Try to modify the shape font settings.
        /// </summary>
        /// <param name="font">Reference to shape font settings to apply</param>
        /// <returns>
        /// <para>
        /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b>
        /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property
        /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in.
        /// </para>
        /// <para>
        /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result
        /// </para>
        /// </returns>
        public IResult SetFont(FontModel font)
        {
            if (font == null)
            {
                return(BooleanResult.CreateErroResult("border can not be null"));
            }

            try
            {
                Shape.Font.SetFromFont(font.ToFont());

                return(BooleanResult.SuccessResult);
            }
            catch (Exception e)
            {
                return(BooleanResult.FromException(e));
            }
        }
コード例 #12
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ScheduleSettingWindow()
        {
            try
            {
                InitializeComponent();
                Title = "NiceAlerm - スケジュール設定 ver " + AppUtil.GetVersion();

                foreach (var font in Fonts.SystemFontFamilies)
                {
                    FontModel model = new FontModel(font.Source);
                    FontComboBox.Items.Add(model);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
0
ファイル: FontTest.cs プロジェクト: limocute/yak2d
        public void FontModel_SubFontAtSize_ReturnCorrectSubfont()
        {
            var subFonts = new List <SubFont>
            {
                new SubFont(12.0f, 0.0f, null, null, false, null),
                new SubFont(18.0f, 0.0f, null, null, false, null),
                new SubFont(24.0f, 0.0f, null, null, false, null),
                new SubFont(32.0f, 0.0f, null, null, false, null),
                new SubFont(48.0f, 0.0f, null, null, false, null),
            };

            var font = new FontModel(subFonts);

            Assert.Equal(32.0f, font.SubFontAtSize(30.0f).Size);
            Assert.Equal(18.0f, font.SubFontAtSize(13.0f).Size);
            Assert.Equal(12.0f, font.SubFontAtSize(6.0f).Size);
            Assert.Equal(12.0f, font.SubFontAtSize(-5.0f).Size);
            Assert.Equal(48.0f, font.SubFontAtSize(128.0f).Size);
        }
コード例 #14
0
ファイル: CutPic.aspx.cs プロジェクト: zoomlacms/web036
    /// <summary>
    /// 将字符串转换为图片,用于水印
    /// </summary>
    /// <imgvpath>生成的文字水印图片存储位置</imgvpath>
    /// <FontModel>字体模型,包含文本,字体颜色,大小等</imgvpath>
    /// <returns></returns>
    public static System.Drawing.Image ConverFontToImg(string imgvpath, FontModel model)
    {
        int width  = model.intsize * model.text.Length * 2;
        int height = model.intsize * 2;
        //-----------根据指定宽高,生成图片
        string imgppath = function.VToP(imgvpath);

        SafeC.CreateDir(imgvpath);
        //System.Drawing.Image image, image2 = System.Drawing.Image.FromFile(imgppath);
        System.Drawing.Image image = new Bitmap(width, height);
        Graphics             g     = Graphics.FromImage(image);

        //g.FillRectangle(new SolidBrush(Color.FromArgb(model.GetRGB(model.background, "red"), model.GetRGB(model.background, "yellow"), model.GetRGB(model.background, "blue"))), 0, 0, width, height); //背景色
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        //------------指定文字与字体样式
        FontStyle fs     = FontStyle.Regular;
        Font      f      = new Font(model.family, model.intsize, fs);
        SizeF     crSize = g.MeasureString(model.text, f);
        //string color = "0x" + "#333333".Replace("#", "");
        //SolidBrush b = new SolidBrush(Color.FromArgb(255, Color.FromArgb(Convert.ToInt32(color, 16))));//定义字体画笔
        SolidBrush   b         = new SolidBrush(Color.FromArgb(model.GetRGB(model.color, "red"), model.GetRGB(model.color, "yellow"), model.GetRGB(model.color, "blue")));
        StringFormat StrFormat = new StringFormat();
        int          ap        = 40;//透明度

        if (ap > 100 || ap < 0)
        {
            ap = 100;
        }
        int        m_alpha = 255 * (ap / 100);
        int        posx = 3, posy = 3;//文字的起始位置
        SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));

        g.DrawString(model.text, f, semiTransBrush2, new PointF(posx + 1, posy + 1), StrFormat);    //?无用
        g.DrawString(model.text, f, b, new PointF(posx, posy), StrFormat);
        g.Dispose();
        return(image);
    }
コード例 #15
0
ファイル: ShowTextDemo.cs プロジェクト: fumobox/FontLoaderZ
    private void Start()
    {
        var source = new FontSource(_font.bytes);

        var fontModel = FontModel.Load(source);

        var codePoints = UnicodeUtility.ToCodePoints(_text);

        _contourPoints = new List <GlyphContourInfoV2>(codePoints.Length);

        var offset = 0f;

        for (var i = 0; i < codePoints.Length; i++)
        {
            try
            {
                var codePoint = codePoints[i];
                var glyph     = fontModel.GetGlyph(codePoint, source);
                var con       = glyph.ToVector2(fontModel, source);
                ShowPoint(con, offset);
                offset += con.AdvancedWidth;
                _contourPoints.Add(con);
            }
            catch (FontException e)
            {
                Debug.LogWarning(e);

                // Replace with a tofu glyph.
                var glyph = fontModel.GetNotDefGlyph(source);
                var con   = glyph.ToVector2(fontModel, source);
                ShowPoint(con, offset);
                offset += con.AdvancedWidth;
                _contourPoints.Add(con);
            }
        }
    }
コード例 #16
0
 public static CompactFontFormatTable Load(uint tableOffset, FontSource p, FontModel font)
 {
     p.Offset = tableOffset;
     return(new CompactFontFormatTable(p, font));
 }
コード例 #17
0
ファイル: BMDrawer.cs プロジェクト: blockspacer/FrankE
        public Bitmap test_draw(ObservableCollection <System.Windows.UIElement> list,
                                ObservableCollection <FontModel> fontList,
                                MaxRectsBinPack binPack,
                                string alphabet,
                                FontSettings fontSettings)
        {
            alphabet = alphabet.Replace("\n", "");
            alphabet = alphabet.Replace("\r", "");
            Library library = new Library();
            Face    face    = library.NewFace(fontSettings.FontName, 0);

            // Find the largest glyph bounding rectangle
            //  Rect glyphRect = getGlyphRect(face, alphabet);
            //int glyphWidth = (int)Math.Ceiling(glyphRect.Width) + 4 * fontSettings.OutlineWidth;
            //int glyphHeight = (int)Math.Ceiling(glyphRect.Height) + 4 * fontSettings.OutlineWidth;
            int glyphWidth  = 18 + 4 * fontSettings.OutlineWidth;
            int glyphHeight = 18 + 4 * fontSettings.OutlineWidth;

            //add new font

            FontModel newFont = new FontModel()
            {
                Id            = (ushort)fontSettings.FontSize,
                size          = fontSettings.FontSize,
                lineheight    = glyphHeight,              // 22,
                spacelength   = (int)(glyphWidth * 0.6f), //todo ?
                baseline      = 0,
                kerning       = -0.5f,
                monowidth     = fontSettings.FontSize + 1,
                letterspacing = 0,
                rangeFrom     = alphabet[0],
                rangeTo       = alphabet[alphabet.Length - 1]
            };

            fontList.Add(newFont);


            Bitmap   bmp = new Bitmap((int)Math.Ceiling((double)fontSettings.ImageWidth), (int)Math.Ceiling((double)fontSettings.ImageHeight));
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(fontSettings.BgColor);
            //g.Clear(Color.Black);q
            int x = 0, y = 0;

            for (int i = 0; i < alphabet.ToCharArray().Length; i++)
            {
                string currentChar0 = alphabet.ToCharArray()[i].ToString();
                uint   glyphIndex   = face.GetCharIndex(uchar2code(currentChar0));


                if (fontSettings.FontSize <= 14)
                {
                    face.SetPixelSizes((uint)0, (uint)fontSettings.FontSize);
                    face.LoadGlyph(glyphIndex, LoadFlags.Default, LoadTarget.Normal);
                    face.Glyph.RenderGlyph(RenderMode.Normal);
                }
                else
                {
                    face.SetCharSize(0, fontSettings.FontSize, 0, 72);
                    face.LoadGlyph(glyphIndex, LoadFlags.ForceAutohint, LoadTarget.Lcd);
                    face.Glyph.RenderGlyph(RenderMode.Lcd);
                }

                //Get character alignment
                float left   = (float)face.Glyph.Metrics.HorizontalBearingX;
                float right  = (float)face.Glyph.Metrics.HorizontalBearingX + (float)face.Glyph.Metrics.Width;
                float top    = (float)face.Glyph.Metrics.HorizontalBearingY;
                float bottom = (float)face.Glyph.Metrics.HorizontalBearingY + (float)face.Glyph.Metrics.Height;
                float FHT    = fontSettings.FontSize;
                int   FHD    = (int)Math.Ceiling(FHT);
                int   kx     = x + face.Glyph.BitmapLeft;
                int   ky     = (int)Math.Round((float)y + (FHD - face.Glyph.BitmapTop));


                ////Select render mode (1 times or 2 times)
                //if (this.grender_mode == "freetype_nearestneighbor")
                //{
                //    face.SetCharSize(0, this.fontHeight * 2, 0, 72);
                //    face.LoadGlyph(glyphIndex, LoadFlags.ForceAutohint, LoadTarget.Lcd);
                //    face.Glyph.RenderGlyph(RenderMode.Lcd);
                //    FTBitmap ftbmp = face.Glyph.Bitmap;
                //    if (ftbmp.Width == 0)
                //    {
                //        x += this.tile_width;
                //        if (x + this.tile_width > this.image_width)
                //        {
                //            x = 0;
                //            y += this.tile_height;
                //        }
                //        continue;
                //    }

                //    Bitmap tmpBmp = ftbmp.ToGdipBitmap(this.penColor);

                //    tmpBmp = kPasteImage(tmpBmp, tile_width * 2, tile_height * 2, (int)face.Glyph.BitmapLeft,
                //                        (int)Math.Round(((float)this.fontHeight * 2 - face.Glyph.BitmapTop)));

                //    Bitmap cBmp = kResizeImage(tmpBmp, tmpBmp.Width / 2, tmpBmp.Height / 2, System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor);
                //    Bitmap nBmp = gray2alpha(cBmp);
                //    cBmp.Dispose();

                //    g.DrawImageUnscaled(nBmp, x + FontSettings.relativePositionX, y + FontSettings.relativePositionY);
                //    nBmp.Dispose();
                //}
                //else if (this.grender_mode == "freetype_HighQualityBicubic")
                //{
                //    face.SetCharSize(0, this.fontHeight * 2, 0, 72);
                //    face.LoadGlyph(glyphIndex, LoadFlags.ForceAutohint, LoadTarget.Lcd);
                //    face.Glyph.RenderGlyph(RenderMode.Lcd);
                //    FTBitmap ftbmp = face.Glyph.Bitmap;
                //    if (ftbmp.Width == 0)
                //    {
                //        x += this.tile_width;
                //        if (x + this.tile_width > this.image_width)
                //        {
                //            x = 0;
                //            y += this.tile_height;
                //        }
                //        continue;
                //    }

                //    Bitmap tmpBmp = ftbmp.ToGdipBitmap(this.penColor);

                //    tmpBmp = kPasteImage(tmpBmp, tile_width * 2, tile_height * 2, (int)face.Glyph.BitmapLeft,
                //        (int)Math.Round(((float)this.fontHeight * 2 - face.Glyph.BitmapTop)));

                //    Bitmap cBmp = kResizeImage(tmpBmp, tmpBmp.Width / 2, tmpBmp.Height / 2, System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic);
                //    Bitmap nBmp = gray2alpha(cBmp);
                //    cBmp.Dispose();

                //    g.DrawImageUnscaled(nBmp, x + FontSettings.relativePositionX, y + FontSettings.relativePositionY);
                //    nBmp.Dispose();

                //}
                //else if (this.grender_mode == "freetype_drawtwice")
                //{
                //    face.LoadGlyph(glyphIndex, LoadFlags.Default, LoadTarget.Normal);
                //    face.Glyph.RenderGlyph(RenderMode.Normal);
                //    FTBitmap ftbmp = face.Glyph.Bitmap;
                //    if (ftbmp.Width == 0)
                //    {
                //        x += this.tile_width;
                //        if (x + this.tile_width > this.image_width)
                //        {
                //            x = 0;
                //            y += this.tile_height;
                //        }
                //        continue;
                //    }
                //    Bitmap cBmp = ftbmp.ToGdipBitmap(this.penColor);
                //    Bitmap sBmp = ftbmp.ToGdipBitmap(this.shadowColor);

                //    Bitmap nBmp = gray2alpha(cBmp);
                //    cBmp.Dispose();

                //    g.DrawImageUnscaled(sBmp, kx + FontSettings.relativePositionX + 1, ky + FontSettings.relativePositionY + 1);//draw twice
                //    g.DrawImageUnscaled(nBmp, kx + FontSettings.relativePositionX, ky + FontSettings.relativePositionY);
                //    cBmp.Dispose();
                //    nBmp.Dispose();

                //}
                //else if (this.grender_mode == "freeyype_nosmoothing")
                //{
                //    face.SetPixelSizes((uint)0, (uint)this.fontHeight);
                //    face.LoadGlyph(glyphIndex, LoadFlags.Monochrome, LoadTarget.Mono);
                //    face.Glyph.RenderGlyph(RenderMode.Mono);
                //    FTBitmap ftbmp = face.Glyph.Bitmap;
                //    if (ftbmp.Width == 0)
                //    {
                //        x += this.tile_width;
                //        if (x + this.tile_width > this.image_width)
                //        {
                //            x = 0;
                //            y += this.tile_height;
                //        }
                //        continue;
                //    }
                //    Bitmap cBmp = ftbmp.ToGdipBitmap(this.penColor);
                //    g.DrawImageUnscaled(cBmp, kx + FontSettings.relativePositionX, ky + FontSettings.relativePositionY);
                //    cBmp.Dispose();
                //}

                //    int tile_width = 24;
                //int tile_height = FontSettings.iFontHeight;//24;
                ////else
                ////{
                FTBitmap ftbmp = face.Glyph.Bitmap;

                //    if (ftbmp.Width == 0)
                //    {
                //        x += tile_width;
                //        if (x + tile_width > this.image_width)
                //        {
                //            x = 0;
                //            y += tile_height;
                //        }
                //        continue;
                //    }


                Bitmap cBmp = ftbmp.ToGdipBitmap(fontSettings.PenColor);
                Bitmap nBmp = gray2alpha(cBmp);

                Rect newPos = binPack.Insert(cBmp.Width, cBmp.Height, MaxRectsBinPack.FreeRectChoiceHeuristic.RectBottomLeftRule);

                //DebugRectangle
                System.Windows.Shapes.Rectangle testRect = new System.Windows.Shapes.Rectangle
                {
                    Stroke          = System.Windows.Media.Brushes.LightGreen,
                    StrokeThickness = 0
                };

                ImageBrush ib = new ImageBrush();
                //    cBmp.MakeTransparent();
                cBmp.Dispose();
                var source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(nBmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                                                                                          System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
                nBmp.Dispose();
                ib.ImageSource  = source;
                testRect.Fill   = ib;
                testRect.Width  = newPos.Width;
                testRect.Height = newPos.Height;
                Canvas.SetLeft(testRect, newPos.Left);
                Canvas.SetTop(testRect, newPos.Top);
                list.Add(testRect);

                Glyph newGlyph = new Glyph()
                {
                    X      = (int)Math.Ceiling(newPos.Left),
                    Y      = (int)Math.Ceiling(newPos.Top),
                    width  = (int)Math.Ceiling(newPos.Width),
                    height = (int)Math.Ceiling(newPos.Height)
                };
                newFont.SetGlyph(currentChar0, newGlyph);

                //if(glyphIndex == 33)
                //{

                //}
                // Construct KerningData
                for (int j = 0; j < alphabet.ToCharArray().Length; j++)
                {
                    string left_Char0      = alphabet.ToCharArray()[j].ToString();
                    uint   left_glyphIndex = face.GetCharIndex(uchar2code(left_Char0));

                    //if (left_glyphIndex == 45)
                    //{

                    //}
                    //char c1 = mAlphabet[i];
                    //FT_UInt c1Index = FT_Get_Char_Index(face, c1);
                    var delta = face.GetKerning(left_glyphIndex, glyphIndex, KerningMode.Default);

                    // KerningData kd = new KerningData(kern_currentChar0, currentChar0, delta.X.ToInt32() >> 6, 0, delta.Y.ToInt32() >> 6, 0);
                    if (left_glyphIndex == 0 || delta.X == 0) //no kerning
                    {
                        continue;
                    }

                    Kerning newKerning = new Kerning();
                    newKerning.RightGlyphID = left_glyphIndex;
                    newKerning.KerningValue = delta.X.ToInt32() >> 6;
                    newFont.SetKerning(left_Char0, newKerning);
                }

                newFont.SetVerticalOffset(currentChar0, ky);

                //cBmp.Dispose();
                //g.DrawImageUnscaled(nBmp, (int)Math.Ceiling(newPos.X) + fontSettings.relativePositionX, (int)Math.Ceiling(newPos.Y) + fontSettings.relativePositionY);
                //// g.DrawImageUnscaled(nBmp, kx + FontSettings.relativePositionX, ky + FontSettings.relativePositionY);
                //nBmp.Dispose();
            }
            g.Dispose();
            library.Dispose();
            return(bmp);
        }
コード例 #18
0
 private void FillFontFamiliesInRibbon()
 {
     RibbonGalleryAllFonts.ItemsSource     = FontModel.OrderBy(x => x.ToString());
     RibbonGalleryAllFontSizes.ItemsSource = FontSizeModel;
 }
コード例 #19
0
ファイル: FontTestController.cs プロジェクト: sebbarg/yagnix
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

              Title = "Font test";

              _view = new UITableView(new CGRect(), UITableViewStyle.Grouped);
              View.Add(_view);

              _view.FitToParent();

              _view.RowHeight = UITableView.AutomaticDimension;
              _view.EstimatedRowHeight = 100;

              var cellFactory = new FontCellFactory();

              var source = new TableSource();
              _view.Source = source;

              Section section;
              UIFont font;
              FontModel fontModel;

              // --------------------------------------------------

              section = new Section();
              source.Sections.Add(section);

              section.Header = "Defaults";

              font = UIFont.PreferredBody;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredBody",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredCaption1;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredCaption1",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredCaption2;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredCaption2",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredFootnote;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredFootnote",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredHeadline;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredHeadline",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              font = UIFont.PreferredSubheadline;
              fontModel = new FontModel {
            Text = $"{font.PointSize} PreferredSubheadline",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              // --------------------------------------------------

              section = new Section();
              source.Sections.Add(section);

              font = UIFont.SystemFontOfSize(UIFont.LabelFontSize);
              section.Header = font.Name;

              fontModel = new FontModel {
            Text = $"{font.PointSize} default label font w/ size",
            Font = font
              };
              section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));

              for ( int size = 3; size <= 60; size += 3 )
              {
            font = UIFont.SystemFontOfSize(size);
            fontModel = new FontModel {
              Text = $"{font.PointSize} the quick brown fox jumps over the lazy dog",
              Font = font
            };
            section.Cells.Add(new CellModel<FontModel>(cellFactory, fontModel));
              }
        }
コード例 #20
0
 public MainViewModel()
 {
     FontModelProp = new FontModel();
     GuessCommand  = new GalaSoft.MvvmLight.CommandWpf.RelayCommand(Guess);
     MessageBox.Show($"{FontModelProp.FontFamily} {FontModelProp.FontSize} {FontModelProp.FontStyle}  {FontModelProp.Foreground} ");
 }
コード例 #21
0
        /// <summary>
        /// Adds a <c>pPr</c> node (Text Paragraph Properties) to the node of type <c>p</c> (Text Paragraphs) specified. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="node"><c>p</c> node (Text Paragraphs).</param>
        /// <param name="model">Font from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <remarks>
        /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_pPr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_pPr-1.html</a>
        /// </remarks>
        public static void AddTextParagraphPropertiesNode(this XmlNode node, FontModel model, IXmlHelper documentHelper)
        {
            var textParagraphPropertiesNode = documentHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "pPr");

            textParagraphPropertiesNode.AddDefaultTextRunPropertiesNode(model, documentHelper);
        }
コード例 #22
0
        private CompactFontFormatTable(FontSource source, FontModel font)
        {
            var tableOffset = source.Offset;

            // Header
            // Skip h_major, h_minor, h_hdrSize, h_offSize
            source.Offset += 4;

            // Ignore Name Index
            LoadIndexData(source);

            // Top Dict Index
            var topDictIndex = LoadIndexData(source);

            // String Index
            var stringIndex = LoadIndexData(source);

            var globalSubrIndex = LoadIndexData(source);

            if (globalSubrIndex != null)
            {
                font.GSubrs     = globalSubrIndex;
                font.GSubrsBias = GetSubrBias(font.GSubrs.Length);
            }

            var topDictArray = LoadTopDicts(source, tableOffset, topDictIndex, stringIndex);

            if (topDictArray.Length != 1)
            {
                throw new FontException($"Too Many TopDict: {topDictArray.Length}");
            }

            font.TopDict = topDictArray[0];

            if (font.TopDict.PrivateDict != null)
            {
                font.DefaultWidthX = font.TopDict.PrivateDict.DefaultWidthX;
                font.NormalWidthX  = font.TopDict.PrivateDict.NormalWidthX;
            }

            font.IsCidFont = font.TopDict.ROS.Item1 != null && font.TopDict.ROS.Item2 != null;

            if (font.IsCidFont)
            {
                if (!font.TopDict.FDArrayIndex.HasValue || font.TopDict.FDArrayIndex.Value == 0)
                {
                    throw new FontException("FDArray is missing.");
                }

                if (!font.TopDict.FDSelectIndex.HasValue || font.TopDict.FDSelectIndex.Value == 0)
                {
                    throw new FontException("FDSelect is missing");
                }

                var fdArrayOffset  = tableOffset + font.TopDict.FDArrayIndex.Value;
                var fdSelectOffset = tableOffset + font.TopDict.FDSelectIndex.Value;

                source.Offset = fdArrayOffset;
                var fdArrayIndex = LoadIndexData(source);
                font.TopDict.FDArray =
                    LoadTopDicts(source, tableOffset, fdArrayIndex, stringIndex);
                font.TopDict.FDSelect =
                    LoadFdSelect(source, fdSelectOffset, font.GlyphCount, (uint)font.TopDict.FDArray.Length);
            }

            var privateDictOffset = tableOffset + font.TopDict.Private[1];
            var privateDict       = CffDictParser.LoadPrivateDict(source.Bytes, privateDictOffset, font.TopDict.Private[0]);

            font.DefaultWidthX = privateDict.DefaultWidthX;
            font.NormalWidthX  = privateDict.NormalWidthX;

            if (privateDict.Subrs != 0)
            {
                var subrOffset = privateDictOffset + privateDict.Subrs;
                source.Offset = subrOffset;
                var subrIndex = LoadIndexData(source);
                font.Subrs     = subrIndex;
                font.SubrsBias = GetSubrBias(font.Subrs.Length);
            }
            else
            {
                font.Subrs     = new ByteSegment[0];
                font.SubrsBias = 0;
            }

            source.Offset    = tableOffset + font.TopDict.CharStrings;
            _charStringIndex = LoadIndexData(source);
        }
コード例 #23
0
        /// <summary>
        /// Adds a <c>pPr</c> node (Text Paragraph Properties) to the node of type <c>p</c> (Text Paragraphs) specified. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="node"><c>p</c> node (Text Paragraphs).</param>
        /// <param name="model">Font from model.</param>
        /// <remarks>
        /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-a_pPr-1.html">http://www.schemacentral.com/sc/ooxml/e-a_pPr-1.html</a>
        /// </remarks>
        private static void AddTextParagraphPropertiesNode(this XmlNode node, FontModel model)
        {
            var textParagraphPropertiesNode = ChartXmlHelper.CreateOrDefaultAndAppendElementToNode(node, "a", "pPr");

            textParagraphPropertiesNode.AddDefaultTextRunPropertiesNode(model);
        }
コード例 #24
0
ファイル: FontTest.cs プロジェクト: limocute/yak2d
 public void FontModel_DealsWithNullOrZeroSizedSubFontArray_ThrowsException()
 {
     Assert.Throws <Yak2DException>(() => { var obj = new FontModel(null); });
     Assert.Throws <Yak2DException>(() => { var obj = new FontModel(new List <SubFont>()); });
 }