⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgfontmetrics.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
字号:
#include <assert.h>#include <string.h>#include "render_interface.h"#include "mgcolor.h"#include "mgpen.h"#include "mgbrush.h"#include "mgrect.h"#include "mgfontmetrics.h"#include "mgpainter.h"#include "mghtml_part.h"MGFontMetrics::MGFontMetrics(){    part = NULL;}MGFontMetrics::~MGFontMetrics(){}MGFontMetrics::MGFontMetrics( const MGPainter* f ){	font = f->cfont;    part = f->cpart;}MGFontMetrics::MGFontMetrics( const MGFont& f, MGHTMLPart* mgpart ){	font = f;    part = mgpart;}MGFontMetrics::MGFontMetrics( const MGFontMetrics& fm ){	font = fm.font;    part = fm.part;}int MGFontMetrics::ascent() const{	return height()-descent()-1;}static PLOGFONT getSafeLogFont (MGHTMLPart* part, const MGFont& font){    PLOGFONT logfont;    if (part)        logfont = part->getFont (font);    else {        logfont = MGFont::CreateFont (font);    }    if (logfont == NULL)        return GetSystemFont (SYSLOGFONT_WCHAR_DEF);    return logfont;}int MGFontMetrics::descent() const{#if 1    PLOGFONT logfont = getSafeLogFont (part, font);    int sbc_descent = logfont->sbc_devfont->font_ops->get_font_descent                 (logfont, logfont->sbc_devfont);    int mbc_descent = 0;    if (logfont->mbc_devfont)        mbc_descent = logfont->mbc_devfont->font_ops->get_font_descent                (logfont, logfont->mbc_devfont);     if (!part && logfont != GetSystemFont (SYSLOGFONT_WCHAR_DEF))        DestroyLogFont (logfont);    return MAX (sbc_descent, mbc_descent);#else	return height()*3/8;#endif}int MGFontMetrics::width( char ) const{    PLOGFONT logfont;    if (part)        logfont = part->getFont (font);    else {        logfont = MGFont::CreateFont (font);    }	PLOGFONT old = SelectFont( HDC_SCREEN, logfont); 	int width = GetMaxFontWidth (HDC_SCREEN);	SelectFont( HDC_SCREEN, old );    if (!part && logfont) DestroyLogFont (logfont);	return width; }int MGFontMetrics::width( MGChar c ) const{	MGString str( c );	return width( str, str.length() );}int MGFontMetrics::width( const MGString& str, int len ) const{	return boundingRect( str, len ).width();}int MGFontMetrics::height() const{#if 1    PLOGFONT logfont = getSafeLogFont (part, font);    int sbc_height = logfont->sbc_devfont->font_ops->get_font_height                (logfont, logfont->sbc_devfont);    int mbc_height = 0;    if (logfont->mbc_devfont)        mbc_height= logfont->mbc_devfont->font_ops->get_font_height                (logfont, logfont->mbc_devfont);     if (!part && logfont != GetSystemFont (SYSLOGFONT_WCHAR_DEF))        DestroyLogFont (logfont);    return MAX (sbc_height, mbc_height);#else	return (font.m_pointSize+2)*4/3;#endif}MGRect MGFontMetrics::boundingRect( const MGChar& c ){	MGString str( c );	return boundingRect( str, str.length() );}MGRect MGFontMetrics::boundingRect( const MGString& str, int len ) const{	SIZE sz;    PLOGFONT logfont;    if (part)        logfont = part->getFont (font);    else {        logfont = MGFont::CreateFont (font);    }	PLOGFONT old = SelectFont (HDC_SCREEN, logfont); 	const char* s = str.ascii();	GetTextExtent (HDC_SCREEN, s, (len < 0)?strlen (str):len, &sz);	SelectFont (HDC_SCREEN, old);    if (!part && logfont) DestroyLogFont (logfont);    if (font.m_italic) sz.cy += (height () >> 1);	return MGRect (0, 0, sz.cx, sz.cy);}int MGFontMetrics::leftBearing( MGChar ) const{	return 0;}int MGFontMetrics::rightBearing( MGChar ) const{    if (font.m_italic)        return height () >> 1;	return 0;}int MGFontMetrics::getFirstCharLen (const MGString& str, int len) const{    PLOGFONT logfont;    if (part)        logfont = part->getFont (font);    else {        logfont = MGFont::CreateFont (font);    }    if (logfont == NULL) logfont = GetSystemFont (SYSLOGFONT_WCHAR_DEF);	const char* sz = str.ascii();    len = GetFirstMCharLen (logfont, sz, len);    if (!part && logfont) DestroyLogFont (logfont);    return len;}int MGFontMetrics::getFirstWordLen (const MGString& str, int len, int* nr_delim) const{    PLOGFONT logfont;    WORDINFO wi;    if (part)        logfont = part->getFont (font);    else {        logfont = MGFont::CreateFont (font);    }    if (logfont == NULL) logfont = GetSystemFont (SYSLOGFONT_WCHAR_DEF);	const char* sz = str.ascii();    GetFirstWord (logfont, sz, len, &wi);    if (!part && logfont) DestroyLogFont (logfont);    if (nr_delim == NULL)        return wi.len + wi.nr_delimiters;    else {        *nr_delim = wi.nr_delimiters;        return wi.len;    }}bool MGFontMetrics::fixedPitch () const{    PLOGFONT logfont = getSafeLogFont (part, font);    bool fixed = false;    if (!strcasecmp (logfont->type, FONT_TYPE_NAME_BITMAP_RAW)) {        fixed = true;    }    else if (!strcasecmp (logfont->type, FONT_TYPE_NAME_BITMAP_VAR)) {        if (logfont->sbc_devfont->font_ops->get_ave_width                 (logfont, logfont->sbc_devfont)             == logfont->sbc_devfont->font_ops->get_max_width                (logfont, logfont->sbc_devfont))        fixed = true;    }    if (!part && logfont != GetSystemFont (SYSLOGFONT_WCHAR_DEF))        DestroyLogFont (logfont);    return fixed;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -