📄 cfont.cpp
字号:
#include "cfont.h"
#include "stdio.h"
#include "string.h"
#define MAX_FONT_NUMBER 1024
//##ModelId=40501B8602F3
CFont::CFont()
{
uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&m_uglFontDrvId);
m_uglFontId = UGL_NULL;
}
//##ModelId=40501B8602F4
CFont::~CFont()
{
DeleteObject();
}
void CFont::SearchAllAvailableFonts(UGL_FONT_DESC **pFontDesc , int * fontNumber)
{
UGL_FONT_DRIVER_ID fontDrvId;
UGL_FONT_DESC * p_FontDesc = new UGL_FONT_DESC[MAX_FONT_NUMBER];
*pFontDesc = p_FontDesc;
uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&fontDrvId);
UGL_SEARCH_ID searchId = uglFontFindFirst(fontDrvId , p_FontDesc);
printf("1: pixelSize min = %d ,pixelSize max = %d, weight min= %d , weight max= %d ,
italic = %d , spacing =% d , charSet = %d ,faceName = %s ,familyName = %s \n",
p_FontDesc[0].pixelSize.min , p_FontDesc[0].pixelSize.max, p_FontDesc[0].weight.min ,
p_FontDesc[0].weight.max , p_FontDesc[0].italic , p_FontDesc[0].spacing ,
p_FontDesc[0].charSet , p_FontDesc[0].faceName , p_FontDesc[0].familyName);
UGL_STATUS status;
int number = 1;
do{
number ++;
p_FontDesc++;
status = uglFontFindNext(fontDrvId , p_FontDesc , searchId);
printf("%d: pixelSize min = %d ,pixelSize max = %d, weight min= %d , weight max= %d ,
italic = %d , spacing =% d , charSet = %d ,faceName = %s ,familyName = %s \n",
number , p_FontDesc[0].pixelSize.min , p_FontDesc[0].pixelSize.max, p_FontDesc[0].weight.min ,
p_FontDesc[0].weight.max , p_FontDesc[0].italic , p_FontDesc[0].spacing ,
p_FontDesc[0].charSet , p_FontDesc[0].faceName , p_FontDesc[0].familyName);
}while(status != UGL_STATUS_FINISHED && number < 1500);
uglFontFindClose(fontDrvId , searchId);
*fontNumber = number;
}
//取字体Id
//##ModelId=40514E48017E
UGL_FONT_ID CFont::GetFontId ()
{
return m_uglFontId;
}
//设置字体Id
//##ModelId=40514E480192
void CFont::SetFontId(UGL_FONT_ID uglFontId)
{
m_uglFontId = uglFontId;
}
//##ModelId=40501B8602FC
const CFont &CFont::operator=(const CFont &right)
{
m_uglFontId = right.m_uglFontId ;
return *this;
}
//##ModelId=40501B8602FE
bool CFont::CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation,
int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut,
BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality,
LPCTSTR nPitchAndFamily, LPCTSTR lpszFacename)
{
UGL_ORD italic = (bItalic == true) ? UGL_FONT_ITALIC:UGL_FONT_UPRIGHT ;
UGL_FONT_DEF fontDef;
char fontDesp[1024];
sprintf(fontDesp,"pixelSize=%d ; faceName=%s ; familyName=%s",
nHeight , lpszFacename ,nPitchAndFamily);
if(bItalic)
sprintf(fontDesp,"%s;italic",fontDesp);
if(nWeight > 50)
sprintf(fontDesp,"%s;bold",fontDesp);
uglFontFindString(m_uglFontDrvId, fontDesp, &fontDef);
m_uglFontId = uglFontCreate(m_uglFontDrvId , &fontDef);
if(m_uglFontId == UGL_NULL)
return false;
//windml_library
return true;
}
//##ModelId=40501B860338
bool CFont::CreateFontIndirect(const LOGFONT* lpLogFont)
{
return CreateFont(lpLogFont->lfHeight, lpLogFont->lfWidth,lpLogFont->lfEscapement,lpLogFont->lfOrientation,
lpLogFont->lfWeight, lpLogFont->lfItalic, lpLogFont->lfUnderline, lpLogFont->lfStrikeOut,
lpLogFont->lfCharSet,lpLogFont->lfOutPrecision,lpLogFont->lfClipPrecision,lpLogFont->lfQuality,
lpLogFont->lfPitchAndFamily,lpLogFont->lfFaceName);
}
bool CFont::DeleteObject()
{
if(m_uglFontId != UGL_NULL)
uglFontDestroy(m_uglFontId);
m_uglFontId = UGL_NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -