GDI对象的初始化

GDI对象的初始化

一、GR_GraphicsFactory对象的初始化
在XAP_App对象的构造函数中创建GR_GraphicsFactory对象。在XAP_Win32App构造函数中,调用GR_GraphicsFactory对象的
registerClass函数初始化m_vAllocators、m_vDescriptors、m_vClassIds集合成员变量,前两个分别是GR_Allocator、GR_Descriptor
函数指针。

二、GR_Graphics对象的初始化
在XAP_Win32FrameImpl::_createDocumentWindow函数中,根据各个窗口句柄创建GR_Graphics对象实例。
/* Create Graphics */
GR_Win32AllocInfo ai(GetDC(m_hwndContainer), m_hwndContainer);
GR_Win32Graphics * pG = (GR_Win32Graphics *)XAP_App::getApp()->newGraphics(ai);
函数内部调用GR_GraphicsFactory对象的newGraphics函数
主要有:m_hwndContainer、m_hwndTopRuler、m_hwndLeftRuler、m_hwndDocument、m_hwndTopRuler、m_hwndLeftRuler
根据窗口句柄创建六个GR_Graphics对象。

三、GR_Font对象的初始化
1、FL_DocLayout对象在初始化时需要PD_Document和GR_Graphics对象的实例。GR_Graphics实例是用m_hwndDocument句柄
创建的对象。

2、创建字体对象实例
FL_DocLayout::findFont中调用GR_Graphics对象的findFont函数查找字体。首先,根据
pszFontFamily, pszFontStyle, pszFontVariant, pszFontWeight, pszFontStretch, pszFontSize属性组成的键,查找
m_hashFontCache集合中是否存在该字体,如果找到返回该字体,否则,创建新的字体。

3、查找字体属性
fp_Run::lookupProperties函数中
const PP_AttrProp * pSpanAP = NULL;
const PP_AttrProp * pBlockAP = NULL;
const PP_AttrProp * pSectionAP = NULL; 
初始化这三个变量。然后调用虚函数_lookupProperties,这个函数中会调用FL_DocLayout的findFont函数查找或创建字体

四、输入字符
1、创建fp_TextRun对象
首先在fl_BlockLayout::_doInsertTextSpan函数中初始化GR_Itemization对象,在fl_BlockLayout::itemizeSpan函数中根据各个元素的字体属性信息查找字体,设置GR_Itemization的语言、字体等,最后调用GR_Win32USPGraphics::itemize函数,初始化GR_Win32USPItem对象。
其次,根据GR_Itemization对象创建fp_TextRun对象,调用fp_TextRun::setItem函数,设置GR_Item对象

2、计算字符的宽度,初始化m_pRenderInfo对象
首先,创建GR_ShapingInfo对象,调用GR_Win32USPGraphics::shape函数,创建GR_Win32USPRenderInfo对象实例
并且初始化
其次,在fp_TextRun::measureCharWidths函数中调用GR_Win32USPGraphics::measureRenderedCharWidths函数,计算字符的宽度。

3、输出字符
在fp_TextRun::_draw函数中画字符。

原文地址:https://www.cnblogs.com/songtzu/p/3539768.html