资源简介

主要采用GDI的GetGlyphOutline进行TrueType字体的提取,参照C++源码的总体处理逻辑。为适应C#编程,一些结构的定义和C++有所不同。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using TrueTypeText.Drawing;
using TrueTypeText.Outline.Data;
using TrueTypeText.Outline;

namespace TrueTypeText
{
    public partial class MainForm : Form
    {
        private IList wordOutlines;
        private Graphics graphics = null;
        private float lineWidth = 1f;

        public MainForm()
        {
            InitializeComponent();
            wordOutlines = new List();

            Font font = new Font(new FontFamily(“宋体“) 100f);
            tbFont.Text = font.ToString();
            tbFont.Tag = font;
        }

        private void MainForm_Load(object sender EventArgs e)
        {
            graphics = this.CreateGraphics();
        }

        private void MainForm_Paint(object sender PaintEventArgs e)
        {
            DrawingContext context = new DrawingContext(e.Graphics);
            using (Pen p = new Pen(Color.Red lineWidth))
            {
                context.Pen = p;
                //画图
                foreach (WordOutlineDrawing outline in wordOutlines)
                {
                    outline.Draw(context);
                }
            }
        }

        private void MainForm_MouseMove(object sender MouseEventArgs e)
        {
            this.Text = string.Format(“({0}{1})“ e.X e.Y);
        }

        private void tvList_AfterSelect(object sender TreeViewEventArgs e)
        {
            DrawingContext context = new DrawingContext(graphics);
            using (Pen pen = new Pen(Color.Blue lineWidth))
            {
                context.Pen = pen;

                if (e.Node.Nodes.Count > 0)
                {//存在子项
                    pen.Color = Color.Green;

                    Cursor.Current = Cursors.WaitCursor;
                    foreach (TreeNode node in e.Node.Nodes)
                    {
                        IDrawing drawing = node.Tag as IDrawing;
                        if (drawing != null)
                        {
                            drawing.Draw(context);
                        }
                        Thread.Sleep(250);
                    }
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    IDrawing drawing = e.Node.Tag as IDrawing;
                    if (drawing != null)
                    {
                        drawing.Draw(context);
                    }
                }
            }
        }

        #region FillWordOutlines

        /// 
        /// 填充所有字符轮廓
        /// 

        private void FillWordOutlines()
        {
            //清空
            wordOutlines.Clear();
            tvList.Nodes.Clear();
            //填充
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        904  2008-10-16 11:16  Outline\ConvertUtil.cs

     文件        727  2008-10-16 11:16  Outline\Data\DLine.cs

     文件        996  2008-10-16 13:17  Outline\Data\DOutline.cs

     文件        955  2008-10-16 13:17  Outline\Data\DPolygon.cs

     文件        666  2008-10-16 11:16  Outline\GdiNativeMethods.cs

     文件       2946  2008-10-16 11:16  Outline\StructDefine.cs

     文件       5517  2008-10-16 11:16  Outline\WordGraph.cs

     文件       9366  2008-10-16 13:20  App.ico

     文件      20363  2008-10-16 13:37  MainForm.resx

     文件        168  2008-10-16 11:20  TrueTypeText.csproj.user

     文件       1175  2008-10-16 13:24  Properties\AssemblyInfo.cs

     文件       2880  2008-10-16 11:19  Properties\Resources.Designer.cs

     文件       5612  2008-10-16 11:19  Properties\Resources.resx

     文件       1097  2008-10-16 11:19  Properties\Settings.Designer.cs

     文件        249  2008-10-16 11:19  Properties\Settings.settings

     文件       9218  2008-10-16 13:37  MainForm.cs

     文件      13718  2008-10-16 13:37  MainForm.Designer.cs

     文件        474  2008-10-16 11:19  Program.cs

     文件       4193  2008-10-16 13:21  TrueTypeText.csproj

     文件        912  2008-10-16 11:19  TrueTypeText.sln

     文件        391  2008-10-16 11:17  Drawing\BeelineDrawing.cs

     文件        385  2008-10-16 11:17  Drawing\CurvelineDrawing.cs

     文件       1125  2008-10-16 11:17  Drawing\DrawingContext.cs

     文件        376  2008-10-16 11:17  Drawing\IDrawing.cs

     文件        544  2008-10-16 11:17  Drawing\IDrawingContext.cs

     文件        667  2008-10-16 11:17  Drawing\LineDrawing.cs

     文件        813  2008-10-16 11:17  Drawing\PolygonDrawing.cs

     文件        384  2008-10-16 11:17  Drawing\PolylineDrawing.cs

     文件       1117  2008-10-16 11:17  Drawing\WordOutlineDrawing.cs

     目录          0  2008-10-16 13:17  Outline\Data

............此处省略6个文件信息

评论

共有 条评论