您现在的位置:网站首页 > 经验分享 > 鞋业CAD软件柔性内核技术:源码[8-3
设计师介绍:

昵称:烦夫子
类别:界面/平面设计师
年龄:37
现所在地:北京

查看该设计师的主页>>

关注好友

统计中心

主页浏览总数:24096
总积分:89
文章数:88
作品数:70

鞋业CAD软件柔性内核技术:源码[8-3

作者:烦夫子  更新时间: 2007-11-19   浏览人数:17471  评论:0  
分享到:
软件源码:
 
                        柔性图形内核之八
                        Font
 
//应用于CAD/CAM图形类程序设计
//我将逐步开放数以十万记的自主版权软件源码,谢谢大家的支持!
//以后将开源的项目: CAD、工控、机械设计图、电子布线图等
 

//
// TEXTSET.CPP
//

#include "stdafx.h"
#include "textset.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


FontFile::FontFile ()
{

}

int FontFile::GetCharData (const char *str, char *buf)
{
 long   code, position;
 unsigned int len;
 unsigned char ch1, ch2;
 LibIndex  index;

 ch1 = str[0];
 ch2 = str[1];
 if (ch1 > 0xa0 && ch2 > 0xa0) // CHINESE
  code = (ch1 - 0xa1) * 94L + (ch2 - 0xa1);
 else { // ASCII
  if (ch1 >= ' ')
   code = ch1 - ' ' + 3;
  else
   code = ch1 - 11;
  }
 position = code * sizeof (LibIndex) + HEADER;

 Seek (position, CFile::begin);
 Read (&index, sizeof (LibIndex));
 len = index.len2 + (index.len1 << 8);

 ASSERT (len < 1024);

 position = (((long)index.add1)<<24) +
    (((long)index.add2)<<16) +
    (((long)index.add3)<<8) +
    index.add4;
 Seek (position, CFile::begin);
 Read (buf, len);

 return len;
}

void FontFile::GetCharStroke (const char *string, Vector& org, FontData& fdata)
{
 int  i, j, k, len, n_points;
 char pbuf[1024];
 Vector temp;

 len = GetCharData (string, pbuf);

 StrokeData *s = new StrokeData[100]; //100

 for (i = j = 0; i < len && j<100;) {
  n_points = pbuf[i++];
  if (n_points == 0) continue;
  s[j].v = new Vector[n_points];
  s[j].num = n_points;
  for (k = 0; k < n_points; k++) {
   temp.x = pbuf[i++];
   temp.y = 128 - pbuf[i++];
   s[j].v[k] = temp / 128.0;
   }
  j++;
  }

 fdata.org = org;
 fdata.num = j;
 fdata.s = new StrokeData[j];
 memcpy (fdata.s, s, j * sizeof (StrokeData));

 delete [] s;
}

(目前有0人发表看法,  我要发表评论
我要评论:
  只有登录后才能评论!
评论者: 匿名游客    (立即登录 或 注册)