示例#1
0
        public void Render(DrawingContext drawingContext, RenderContext renderContext)
        {
            Int32         lineCount       = _editor.Document.LineCount;
            Int32         lineNumberCount = GetLineNumberCount(lineCount);
            Typeface      typeface        = TypefaceGenerator.GetInstance().GenerateTypeface(_editor.GlyphOption.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            GlyphTypeface glyphTypeface   = TypefaceGenerator.GetInstance().GenerateGlyphTypeface(_editor.GlyphOption.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            UInt16        indice          = glyphTypeface.CharacterToGlyphMap['0'];
            Double        characterWidth  = glyphTypeface.AdvanceWidths[indice] * _editor.GlyphOption.FontSize;
            Double        characterHeight = glyphTypeface.AdvanceHeights[indice] * _editor.GlyphOption.FontSize;
            Double        maxNumberWidth  = Math.Max(lineNumberCount * characterWidth, 3 * characterWidth);
            Point         renderOffset    = new Point(renderContext.Offset.X - _editor.HorizontalOffset, _editor._lineRenderer.RenderOffset.Y + _editor.Padding.Top);
            var           brush           = new SolidColorBrush(CommonUtilities.ColorFromHexString("#FF7D7D7D"));

            foreach (VisualLine visualLine in _editor._lineRenderer.VisibleLines)
            {
                var   formattedText      = new FormattedText(visualLine.Line.LineNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, _editor.GlyphOption.FontSize, brush);
                Point actualRenderOffset = renderOffset;
                actualRenderOffset.X += maxNumberWidth - formattedText.Width;
                actualRenderOffset.Y += (_editor.GlyphOption.LineHeight - characterHeight);
                drawingContext.DrawText(formattedText, actualRenderOffset);
                renderOffset.Y += _editor.GlyphOption.LineHeight;
            }
            drawingContext.DrawLine(new Pen(brush, 2.0), new Point(_editor._lineRenderer.RenderOffset.X + maxNumberWidth + 5.0, _editor._lineRenderer.RenderOffset.Y), new Point(_editor._lineRenderer.RenderOffset.X + maxNumberWidth + 5.0, 2000.0));

            RenderWidth = maxNumberWidth + 10.0;

            renderContext.PushTranslation(RenderWidth, 0.0);
        }
示例#2
0
 public void Add(GlyphTypeface gtf, string path)
 {
     if (Normal == null)
     {
         Normal = path;
     }
     if (gtf.Style == System.Windows.FontStyles.Italic)
     {
         if (isBoldFont(gtf))
         {
             BoldItalic = path;
         }
         else
         {
             Italic = path;
         }
     }
     else
     {
         if (isBoldFont(gtf))
         {
             Bold = path;
         }
         else
         {
             Normal = path;
         }
     }
 }
    public override bool AllowText(TextRenderInfo renderInfo)
    {
        DocumentFont  font     = renderInfo.GetFont();
        PdfDictionary fontDict = font.FontDictionary;
        PdfName       subType  = fontDict.GetAsName(PdfName.SUBTYPE);

        if (PdfName.TYPE0.Equals(subType))
        {
            PdfArray      descendantFonts = fontDict.GetAsArray(PdfName.DESCENDANTFONTS);
            PdfDictionary descendantFont  = descendantFonts[0] as PdfDictionary;
            PdfDictionary fontDescriptor  = descendantFont.GetAsDict(PdfName.FONTDESCRIPTOR);
            PdfStream     fontStream      = fontDescriptor.GetAsStream(PdfName.FONTFILE2);
            byte[]        fontData        = PdfReader.GetStreamBytes((PRStream)fontStream);
            MemoryStream  dataStream      = new MemoryStream(fontData);
            dataStream.Position = 0;
            MemoryPackage        memoryPackage = new MemoryPackage();
            Uri                  uri           = memoryPackage.CreatePart(dataStream);
            GlyphTypeface        glyphTypeface = new GlyphTypeface(uri);
            ICollection <string> names         = glyphTypeface.FamilyNames.Values;
            return(names.Where(name => name.Contains("Arial")).Count() > 0);
        }
        else
        {
            // analogous code for other font subtypes
            return(false);
        }
    }
示例#4
0
 private void btn_setfont_Click(object sender, RoutedEventArgs e)
 {
     if (cmb_fonts.SelectedIndex == -1)
     {
         return;
     }
     // Get fonts names
     using (var memoryPackage = new MemoryPackage())
     {
         using (var fontStream = new MemoryStream(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/") + cmb_fonts.SelectedItem.ToString())))
         {
             GlyphTypeface glyphTypeface;
             var           typefaceSource = memoryPackage.CreatePart(fontStream);
             glyphTypeface     = new GlyphTypeface(typefaceSource);
             fontName          = String.Join(" ", glyphTypeface.FamilyNames.Values.ToArray <string>());
             lbl_textFont.Text = "Selected Font Name: " + fontName;
             memoryPackage.DeletePart(typefaceSource);
         }
     }
     //
     lbl_text.FontFamily  = new FontFamily("file:///" + AppDomain.CurrentDomain.BaseDirectory + cmb_fonts.SelectedItem.ToString().Substring(1) + "#" + fontName);
     lbl_text2.FontFamily = new FontFamily("file:///" + AppDomain.CurrentDomain.BaseDirectory + cmb_fonts.SelectedItem.ToString().Substring(1) + "#" + fontName);
     lbl_text3.FontFamily = new FontFamily("file:///" + AppDomain.CurrentDomain.BaseDirectory + cmb_fonts.SelectedItem.ToString().Substring(1) + "#" + fontName);
     lbl_textFont2.Text   = "Textblock said it's: " + String.Join(" ", lbl_text.FontFamily.FamilyNames.Values.ToArray <string>());
 }
        public override RSize MeasureString(string str, RFont font)
        {
            double        width         = 0;
            GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface;

            if (glyphTypeface != null)
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (glyphTypeface.CharacterToGlyphMap.ContainsKey(str[i]))
                    {
                        ushort glyph        = glyphTypeface.CharacterToGlyphMap[str[i]];
                        double advanceWidth = glyphTypeface.AdvanceWidths[glyph];
                        width += advanceWidth;
                    }
                    else
                    {
                        width = 0;
                        break;
                    }
                }
            }

            if (width <= 0)
            {
                var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, Brushes.Red);
                return(new RSize(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height));
            }

            return(new RSize(width * font.Size * 96d / 72d, font.Height));
        }
        private static sbyte ToPixels(double designSize, double emSize, GlyphTypeface typeface)
        {
            dynamic typefaceFriend = new AccessPrivateWrapper(typeface);
            ushort  designEmHeight = typefaceFriend.DesignEmHeight;

            return((sbyte)(designSize / designEmHeight * (emSize * 96.0 / 72.0)));
        }
示例#7
0
        /// <summary>
        /// Compute unshaped glyph run object from the specified character-based info
        /// </summary>
        internal sealed override GlyphRun ComputeUnshapedGlyphRun(
            Point origin,
            char[]        characterString,
            IList <double> characterAdvances
            )
        {
            bool          nullFont;
            GlyphTypeface glyphTypeface = GetGlyphTypeface(out nullFont);

            Invariant.Assert(glyphTypeface != null);

            return(glyphTypeface.ComputeUnshapedGlyphRun(
                       origin,
                       new CharacterBufferRange(
                           characterString,
                           0, // offsetToFirstChar
                           characterString.Length
                           ),
                       characterAdvances,
                       _emSize,
                       (float)_properties.PixelsPerDip,
                       _properties.FontHintingEmSize,
                       nullFont,
                       CultureMapper.GetSpecificCulture(_properties.CultureInfo),
                       (_shapeTypeface == null || _shapeTypeface.DeviceFont == null) ? null : _shapeTypeface.DeviceFont.Name,
                       _textFormattingMode
                       ));
        }
示例#8
0
        private static bool GetTextBounds(GlyphTypeface glyphTypeface, double fontSize, out double topDistance, out double bottomDistance)
        {
            string testCharacters = "aA. ÅÄÖÃÂ_[]{}()|ygf";

            topDistance    = double.MaxValue;
            bottomDistance = double.MinValue;

            for (int n = 0; n < testCharacters.Length; n++)
            {
                if (glyphTypeface.CharacterToGlyphMap.TryGetValue(testCharacters[n], out ushort glyphIndex))
                {
                    Geometry outline = glyphTypeface.GetGlyphOutline(glyphIndex, fontSize, 0);
                    topDistance    = Math.Min(topDistance, outline.Bounds.Top);
                    bottomDistance = Math.Max(bottomDistance, outline.Bounds.Bottom);
                }
            }

            if (bottomDistance == double.MinValue)
            {
                return(false);
            }

            topDistance = Math.Abs(topDistance);
            return(true);
        }
示例#9
0
 public void Stub01()
 {
     // <SnippetGlyphTypefaceSnippet1>
     // Create a glyph typeface by referencing the Kootenay OpenType font.
     GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri("file:///C:\\WINDOWS\\Fonts\\Kooten.ttf"));
     // </SnippetGlyphTypefaceSnippet1>
 }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <c>TextStyle</c> class.
        /// </summary>
        /// <param name="name">Text style name.</param>
        /// <param name="font">Text style font file name with full or relative path.</param>
        /// <param name="checkName">Specifies if the style name has to be checked.</param>
        /// <remarks>If the font file is a true type and is not found in the specified path, the constructor will try to find it in the system font folder.</remarks>
        internal TextStyle(string name, string font, bool checkName)
            : base(name, DxfObjectCode.TextStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "The text style name should be at least one character long.");
            }

            if (string.IsNullOrEmpty(font))
            {
                throw new ArgumentNullException(nameof(font));
            }

            this.IsReserved     = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);
            this.font           = font;
            this.bigFont        = null;
            this.widthFactor    = 1.0;
            this.obliqueAngle   = 0.0;
            this.height         = 0.0;
            this.isVertical     = false;
            this.isBackward     = false;
            this.isUpsideDown   = false;
            this.glyphTypeface  = null;
            this.fontFamilyName = Path.GetFileNameWithoutExtension(font);

            this.TrueTypeFontCheck(font);
        }
示例#11
0
        /// <summary>
        /// simple wrapper routine for generating a glyph run
        /// </summary>
        /// <param name="info"></param>
        /// <param name="glyphTypeface"></param>
        /// <param name="symbolSize"></param>
        /// <param name="pixelsPerDip"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static GlyphRun GetGlyphRun(GlyphInfo info, GlyphTypeface glyphTypeface, double symbolSize, float pixelsPerDip, Point point)
        {
            var run = new GlyphRun(glyphTypeface, 0, false, symbolSize, pixelsPerDip, info.Indexes, point, info.AdvanceWidths,
                                   null, null, null, null, null, null);

            return(run);
        }
示例#12
0
        private PDFObject GetWidths(GlyphTypeface glyphTypeface, IIndirectObjectCreator creator,
                                    IDictionary <int, ushort> cmap)
        {
            PDFArray widths = creator.CreateIndirectArray();
            IDictionary <ushort, double> advWidths = glyphTypeface.AdvanceWidths;

            for (char ch = (char)firstChar; ch <= lastChar; ch++)
            {
                int width = 0;
                if (subsetCharacters.Contains(ch))
                {
                    ushort gid;
                    if (cmap.TryGetValue((int)ch, out gid))
                    {
                        double widthDouble;
                        if (advWidths.TryGetValue(gid, out widthDouble))
                        {
                            width = (int)(1000 * widthDouble);
                        }
                    }
                }
                widths.Array.Add(new PDFInt(width));
            }

            return(widths);
        }
示例#13
0
        /// <summary>
        /// Calculates / Renders the Main Geometry object
        /// </summary>
        /// <returns></returns>
        private void BuildGeometry()
        {
            Uri           ttfPathUri    = new Uri(TtfPath);
            GlyphTypeface glyphTypeface = new GlyphTypeface(ttfPathUri);

            ushort[] glyphIndexes  = new ushort[Text.Length];
            double[] advanceWidths = new double[Text.Length];

            for (int n = 0; n < Text.Length; n++)
            {
                ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[Text[n]];
                glyphIndexes[n] = glyphIndex;

                double width = glyphTypeface.AdvanceWidths[glyphIndex] * HintingEmSize;
                advanceWidths[n] = width;
            }

            GlyphRun wholeString = new GlyphRun(
                glyphTypeface, //glyphTypeface
                0,             //bidiLevel Specifies the bidirectional layout level. Even-numbered and zero values imply left-to-right layout; odd-numbered values imply right-to-left layout.
                false,         //isSideways
                HintingEmSize, //renderingEmSize
                glyphIndexes,  //glyphIndices (IList<ushort>)
                Offset,        //Point baselineOrigin
                advanceWidths, //IList<double> advancedWiths
                null,          //IList<Point> glyphOffsets
                null,          //IList<char> characters
                null,          //string deviceFontName
                null,          //IList<ushort> clustermap
                null,          //IList<bool>caretStops
                null           //System.Windows.MarkupLanguage
                );

            TextAsGeometry = wholeString.BuildGeometry();
        }
示例#14
0
        AcquireCacheItem(
            GlyphTypeface glyphTypeface
            )
        {
            FEMCacheItem         manager = null;
            Uri                  fontUri;
            CodeAccessPermission uriDiscoveryPermission = glyphTypeface.CriticalUriDiscoveryPermission;

            if (uriDiscoveryPermission != null)
            {
                uriDiscoveryPermission.Assert();
            }

            try
            {
                fontUri = glyphTypeface.FontUri;
            }
            finally
            {
                if (uriDiscoveryPermission != null)
                {
                    CodeAccessPermission.RevertAssert();
                }
            }

            if (!_fontEmbeddingManagerCache.TryGetValue(fontUri, out manager))
            {
                manager = new FEMCacheItem(glyphTypeface, _packagingPolicy);
                _fontEmbeddingManagerCache.Add(fontUri, manager);
            }

            return(manager);
        }
示例#15
0
 public Font(Typeface face, string name, GlyphTypeface gface)
 {
     Face          = face;
     FaceName      = name;
     GlyphTypeface = gface;
     _glyphs       = new Lazy <List <Glyph> >(LoadGlyphs);
     _properties   = new Lazy <List <FontProperty> >(LoadProperties);
 }
示例#16
0
 public Font(GlyphTypeface glyph, string familyName, string faceName, FileInfo path)
 {
     this.glyph      = glyph;
     this.familyName = familyName;
     this.faceName   = faceName;
     familyFaceName  = string.Join(" ", familyName, faceName);
     this.path       = path;
 }
示例#17
0
 public CharInfo(char character, GlyphTypeface font, double size, int fontId, TexFontMetrics metrics)
 {
     this.Character = character;
     this.Font      = font;
     this.Size      = size;
     FontId         = fontId;
     this.Metrics   = metrics;
 }
示例#18
0
        private static GlyphRun CreateGlyphRun(double x, double y, Matrix m, double selfLeft,
                                               GlyphTypeface glyphType, double fontSize, List <ushort> indexes, List <double> widths)
        {
            //originを物理ピクセルに合わせる。selfLeftはレンダリング時に加算されるので混ぜてはいけない
            Point origin = new Point(Math.Ceiling(x * m.M11) / m.M11 - selfLeft, Math.Ceiling(y * m.M22) / m.M22);

            return(new GlyphRun(glyphType, 0, false, fontSize, indexes, origin, widths, null, null, null, null, null, null));
        }
示例#19
0
        private IEnumerable <ushort> GetLookupIndicesFromFeatureTable(GlyphTypeface typeface, dynamic featureTable)
        {
            dynamic fontTable = this.GetFontTable(typeface);

            return(this.GetEnumerableFromInternalList(
                       () => featureTable.LookupCount(fontTable.Wrapped),
                       p => (ushort)featureTable.LookupIndex(fontTable.Wrapped, p)));
        }
示例#20
0
 public GlyphDescriptor(GlyphTypeface typeface, int character)
 {
     Typeface      = typeface;
     Index         = Typeface.CharacterToGlyphMap[character];
     CharacterName = ((char)character).ToString();
     Offset        = new Point(0, 0);
     Size          = 1;
 }
示例#21
0
 internal ShapedBuffer(ReadOnlySlice <char> text, ArraySlice <GlyphInfo> glyphInfos, GlyphTypeface glyphTypeface, double fontRenderingEmSize, sbyte bidiLevel)
 {
     Text                = text;
     GlyphInfos          = glyphInfos;
     GlyphTypeface       = glyphTypeface;
     FontRenderingEmSize = fontRenderingEmSize;
     BidiLevel           = bidiLevel;
 }
示例#22
0
            internal GlyphWidths(StringRange range, GlyphTypeface typeFace, double fontSize)
            {
                _range    = range;
                _typeFace = typeFace;
                _scale    = fontSize / _typeFace.DesignEmHeight;

                InitGlyphWidths();
            }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <c>TextStyle</c> class.
        /// </summary>
        /// <param name="name">Text style name.</param>
        /// <param name="font">Text style font file name with full or relative path.</param>
        /// <param name="checkName">Specifies if the style name has to be checked.</param>
        /// <remarks>If the font file is a true type and is not found in the specified path, the constructor will try to find it in the system font folder.</remarks>
        internal TextStyle(string name, string font, bool checkName)
            : base(name, DxfObjectCode.TextStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "The text style name should be at least one character long.");
            }

            if (string.IsNullOrEmpty(font))
            {
                throw new ArgumentNullException(nameof(font));
            }

            this.IsReserved     = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);
            this.font           = font;
            this.widthFactor    = 1.0;
            this.obliqueAngle   = 0.0;
            this.height         = 0.0;
            this.isVertical     = false;
            this.isBackward     = false;
            this.isUpsideDown   = false;
            this.glyphTypeface  = null;
            this.fontFamilyName = Path.GetFileNameWithoutExtension(font);

            // the following information is only applied to ttf not shx fonts
            if (!Path.GetExtension(font).Equals(".ttf", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // try to find the file in the specified directory, if not try it in the fonts system folder
            string fontFile;

            if (File.Exists(font))
            {
                fontFile = Path.GetFullPath(font);
            }
            else
            {
                string file = Path.GetFileName(font);
                fontFile = string.Format("{0}{1}{2}", Environment.GetFolderPath(Environment.SpecialFolder.Fonts), Path.DirectorySeparatorChar, file);
                // if the ttf does not even exist in the font system folder
                if (!File.Exists(fontFile))
                {
                    return;
                }
                this.font = file;
            }
            this.glyphTypeface  = new GlyphTypeface(new Uri(fontFile));
            this.fontFamilyName = this.glyphTypeface.FamilyNames[CultureInfo.GetCultureInfo(1033)];
            if (string.IsNullOrEmpty(this.fontFamilyName))
            {
                ICollection <string> names      = this.glyphTypeface.FamilyNames.Values;
                IEnumerator <string> enumerator = names.GetEnumerator();
                enumerator.MoveNext();
                this.fontFamilyName = enumerator.Current;
            }
        }
示例#24
0
        public ShapedBuffer ShapeText(ReadOnlySlice <char> text, GlyphTypeface typeface, double fontRenderingEmSize,
                                      CultureInfo culture, sbyte bidiLevel)
        {
            using (var buffer = new Buffer())
            {
                buffer.AddUtf16(text.Buffer.Span, text.Start, text.Length);

                MergeBreakPair(buffer);

                buffer.GuessSegmentProperties();

                buffer.Direction = (bidiLevel & 1) == 0 ? Direction.LeftToRight : Direction.RightToLeft;

                buffer.Language = new Language(culture ?? CultureInfo.CurrentCulture);

                var font = ((GlyphTypefaceImpl)typeface.PlatformImpl).Font;

                font.Shape(buffer);

                if (buffer.Direction == Direction.RightToLeft)
                {
                    buffer.Reverse();
                }

                font.GetScale(out var scaleX, out _);

                var textScale = fontRenderingEmSize / scaleX;

                var bufferLength = buffer.Length;

                var shapedBuffer = new ShapedBuffer(text, bufferLength, typeface, fontRenderingEmSize, bidiLevel);

                var glyphInfos = buffer.GetGlyphInfoSpan();

                var glyphPositions = buffer.GetGlyphPositionSpan();

                for (var i = 0; i < bufferLength; i++)
                {
                    var sourceInfo = glyphInfos[i];

                    var glyphIndex = (ushort)sourceInfo.Codepoint;

                    var glyphCluster = (int)sourceInfo.Cluster;

                    var glyphAdvance = GetGlyphAdvance(glyphPositions, i, textScale);

                    var glyphOffset = GetGlyphOffset(glyphPositions, i, textScale);

                    var targetInfo =
                        new Avalonia.Media.TextFormatting.GlyphInfo(glyphIndex, glyphCluster, glyphAdvance,
                                                                    glyphOffset);

                    shapedBuffer[i] = targetInfo;
                }

                return(shapedBuffer);
            }
        }
示例#25
0
 public FpsCounter(GlyphTypeface typeface)
 {
     for (var c = FirstChar; c <= LastChar; c++)
     {
         var s     = new string((char)c, 1);
         var glyph = typeface.GetGlyph((uint)(s[0]));
         _runs[c - FirstChar] = new GlyphRun(typeface, 18, new ReadOnlySlice <char>(s.AsMemory()), new ushort[] { glyph });
     }
 }
        private ushort GetGlyphFromCharacter(GlyphTypeface glyphTypeface, char character)
        {
            ushort glyphIndex;

            // TryGetValue will return zero glyph index for missing code points,
            // which is the right thing to display per http://www.microsoft.com/typography/otspec/cmap.htm
            glyphTypeface.CharacterToGlyphMap.TryGetValue(character, out glyphIndex);
            return(glyphIndex);
        }
示例#27
0
 internal ShapeTypeface(
     GlyphTypeface glyphTypeface,
     IDeviceFont deviceFont
     )
 {
     Invariant.Assert(glyphTypeface != null);
     _glyphTypeface = glyphTypeface;
     _deviceFont    = deviceFont;
 }
示例#28
0
 /// <summary>
 /// 创建<see cref="GlyphInfo"/>对象
 /// </summary>
 /// <param name="typeface"></param>
 /// <param name="renderGlyphTypeface"></param>
 /// <param name="originGlyphTypeface"></param>
 /// <param name="unicodeChar"></param>
 /// <param name="glyphIndex"></param>
 public GlyphInfo(Typeface typeface, GlyphTypeface renderGlyphTypeface, GlyphTypeface originGlyphTypeface,
                  char unicodeChar, ushort glyphIndex)
 {
     Typeface            = typeface;
     RenderGlyphTypeface = renderGlyphTypeface;
     OriginGlyphTypeface = originGlyphTypeface;
     UnicodeChar         = unicodeChar;
     GlyphIndex          = glyphIndex;
 }
示例#29
0
        private IEnumerable <ushort> GetOptionalFeatureIndices(GlyphTypeface typeface, Tag script, Tag langSys)
        {
            dynamic fontTable              = this.GetFontTable(typeface);
            dynamic langSysTable           = this.GetLangSysTable(script, langSys, fontTable);
            var     optionalFeatureIndices = this.GetEnumerableFromInternalList(
                () => langSysTable.FeatureCount(fontTable.Wrapped), p => (ushort)langSysTable.GetFeatureIndex(fontTable.Wrapped, p));

            return(optionalFeatureIndices);
        }
示例#30
0
        /*
         * PathGeometry pg = m_libCmn.GetFontPathGeometry("あ", 20.0, "HGP白洲太楷書体");
         * // "MS 明朝");
         * // "DF平成ゴシック体W9");
         * // "ヒラギノ特太行書");
         */
        public ClsFontPathGeometry GetFontPathGeometry(string str, double fontsize, string fontname)
        {
            char                ch;
            Uri                 uri;
            ushort              glyphIndex;
            Typeface            typeFace;
            GlyphTypeface       gt;
            Geometry            gm;
            ClsFontPathGeometry clsFGP;
            string              name, fontkey;
            int                 max, idx;

            ch          = Convert.ToChar(str);
            m_dFontSize = fontsize;
            typeFace    = new Typeface(fontname);

            RegistryKey regkey =
                Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts", false);

            string[] keys = regkey.GetValueNames();
            fontkey = "";
            max     = keys.Length;
            for (idx = 0; idx < max; idx++)
            {
                if (keys[idx].Contains(fontname) == true)
                {
                    fontkey = keys[idx];
                    break;
                }
            }
            if (fontkey == "")
            {
                FontFamily fm = new FontFamily(fontname);
                // fm.FamilyNames.TryGetValue(XmlLanguage.GetLanguage("en-us"), out name);
                name = fm.FamilyNames.Values.ToList()[0];
                for (idx = 0; idx < max; idx++)
                {
                    if (keys[idx].Contains(name) == true)
                    {
                        fontkey = keys[idx];
                        break;
                    }
                }
            }
            string ttname = (string)regkey.GetValue(fontkey);

            uri = new Uri("C:\\Windows\\Fonts\\" + ttname);
            //uri = new Uri(fontpath);
            gt = new GlyphTypeface(uri);
            gt.CharacterToGlyphMap.TryGetValue((int)ch, out glyphIndex);

            gm            = gt.GetGlyphOutline(glyphIndex, fontsize, fontsize);
            clsFGP        = new ClsFontPathGeometry();
            clsFGP.pg     = gm.GetOutlinedPathGeometry();
            clsFGP.dMoveY = (gt.Baseline) * fontsize;
            return(clsFGP);
        }
示例#31
0
文件: Typeface.cs 项目: dfr0/moon
		internal Typeface (GlyphTypeface gtf)
		{
			typeface = gtf;
		}
示例#32
0
文件: Typeface.cs 项目: dfr0/moon
		public bool TryGetGlyphTypeface (out GlyphTypeface glyphTypeface)
		{
			glyphTypeface = typeface;
			return typeface != null;
		}