在 duilib 中,我們可以定義多種字型,不同的控制項使用不同的字型來豐富我們的介面,今天我們來介紹一下 duilib 是如何使用字型的。
首先,duilib 中定義字型的方法如下:
name="microsoft yahei" size="12" bold="false" italic="false" default="true"/>
id="1"
name="microsoft yahei" size="14" bold="false" italic="false"/>
id="2"
name="microsoft yahei" size="16" bold="false" italic="false"/>
id="3"
name="microsoft yahei" size="18" bold="false" italic="false"/>
在之前的 xml 解析篇中,我們已經知道, xml 解析是按節點進行解析的。型別的節點也有對應的
cmarkupnode
物件被儲存起來,解析完成後,根據cmarkupnode
建立控制項等內容時,當遇到節點,則解析出對應的屬性,將建立的字型儲存在
cpaintmanagerui
中。
接下來看一下字型儲存的資料結構是什麼樣的,字型資訊被儲存在乙個 map 中,型別為 :cduistringptrmap
。 key 是字型的 id, value 是tfontinfo*
型別的字型資訊,當需要取得某控制項的字型屬性時,則呼叫tfontinfo* cpaintmanagerui::getfontinfo(int id)
獲取到對應的字型資訊來繪製文字。 那麼tfontinfo*
型別物件又是如何建立的呢?接下來我們來看一下cpaintmanagerui::addfont
中的關鍵**:
logfont lf = ;
::getobject(::getstockobject(default_gui_font), sizeof(logfont), &lf);
_tcsncpy(lf.lffacename, pstrfontname, lf_facesize);
lf.lfcharset = default_charset;
lf.lfheight =
-nsize;
if( bbold ) lf.lfweight += fw_bold;
if( bunderline ) lf.lfunderline =
true;
if( bitalic ) lf.lfitalic =
true;
hfont hfont =
::createfontindirect(&lf);
if( hfont ==
null ) return
null;
tfontinfo* pfontinfo =
new tfontinfo;
if( !pfontinfo ) return
false;
::zeromemory(pfontinfo, sizeof(tfontinfo));
pfontinfo->hfont = hfont;
pfontinfo->sfontname = pstrfontname;
pfontinfo->isize = nsize;
pfontinfo->bbold = bbold;
pfontinfo->bunderline = bunderline;
pfontinfo->bitalic = bitalic;
if( m_hdcpaint )
在windows內部,字型是以乙個名為 logfont 的結構來表示(參見:logfont)。第二行中的**獲取了介面預設的 logfont 資訊,然後根據函式的傳入引數改變對應的屬性值,得到新的 logfont 資訊後,呼叫createfontindirect
獲取到hfont
,這個就是我們繪製文字時需要用到的字型控制代碼。 下一段**就是建立tfontinfo
型別物件,**很簡單,這裡只說一下::gettextmetrics(m_hdcpaint, &pfontinfo->tm)
這行**,根據指定的hfont
,獲取對應的textmetric
資訊。 Duilib 原始碼分析(四)控制項繪製
渲染引擎crenderengine 封裝gdi duilib master duilib core uirender.h class duilib api crenderengine duilib master duilib core uirender.cpp void crenderengine ...
Duilib 原始碼分析(一)示例推演
duilib示範例子 使用duilib編寫乙個介面軟體,本質上還是乙個win32的軟體,只不過這個軟體的介面不使用windows自帶的控制項,而是交給duilib繪製介面。關於訊息處理,底層還是處理window訊息,但duilib會進一步轉化成duilib訊息,方便編寫響應的邏輯。最簡單的win32...
Memcached原始碼分析之網路模型篇
memcached 採用多執行緒的工作方式,主線程接收連線,然後把連線平攤給 工作執行緒,工作執行緒處理業務邏輯,memcached 使用 libevent 處理網路 事件,主線程和工作執行緒都有乙個 event base,這是 libevent 的核心資料 結構,event base 能夠監聽多個...