| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | #include "..\enodes.h"
 | 
					
						
							|  |  |  | #include "..\Win\winbase.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::EFont::EFont() | 
					
						
							|  |  |  | 	: m_pTextFormat(nullptr) | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 	, m_Color(EColor::WHITE) | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	, m_fFontSize(22) | 
					
						
							|  |  |  | 	, m_FontWeight(EFontWeight::REGULAR) | 
					
						
							|  |  |  | 	, m_bItalic(false) | 
					
						
							|  |  |  | 	, m_bRecreateNeeded(true) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | e2d::EFont::EFont(EString fontFamily, float fontSize /* = 22 */, UINT32 color /* = EColor::WHITE */, UINT32 fontWeight, bool italic /* = false */) | 
					
						
							| 
									
										
										
										
											2017-11-07 22:20:46 +08:00
										 |  |  | 	: EFont() | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	this->setFamily(fontFamily); | 
					
						
							|  |  |  | 	this->setSize(fontSize); | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 	this->setColor(color); | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 	this->setWeight(fontWeight); | 
					
						
							|  |  |  | 	this->setItalic(italic); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::EFont::~EFont() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SafeReleaseInterface(&m_pTextFormat); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | float e2d::EFont::getFontSize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_fFontSize; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | UINT32 e2d::EFont::getFontWeight() const | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_FontWeight; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | UINT32 e2d::EFont::getColor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_Color; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | bool e2d::EFont::isItalic() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_bItalic; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-09 18:22:41 +08:00
										 |  |  | void e2d::EFont::setFamily(const EString & fontFamily) | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_sFontFamily = fontFamily; | 
					
						
							|  |  |  | 	m_bRecreateNeeded = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::EFont::setSize(float fontSize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_fFontSize = fontSize; | 
					
						
							|  |  |  | 	m_bRecreateNeeded = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | void e2d::EFont::setWeight(UINT32 fontWeight) | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_FontWeight = fontWeight; | 
					
						
							|  |  |  | 	m_bRecreateNeeded = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | void e2d::EFont::setColor(UINT32 color) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_Color = color; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | void e2d::EFont::setItalic(bool value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_bItalic = value; | 
					
						
							|  |  |  | 	m_bRecreateNeeded = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::EFont::_initTextFormat() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SafeReleaseInterface(&m_pTextFormat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HRESULT hr = GetDirectWriteFactory()->CreateTextFormat( | 
					
						
							|  |  |  | 		m_sFontFamily.c_str(), | 
					
						
							|  |  |  | 		NULL,                          // Font collection(NULL sets it to the system font collection)
 | 
					
						
							| 
									
										
										
										
											2017-10-26 17:17:30 +08:00
										 |  |  | 		DWRITE_FONT_WEIGHT(m_FontWeight), | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  | 		m_bItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, | 
					
						
							|  |  |  | 		DWRITE_FONT_STRETCH_NORMAL, | 
					
						
							|  |  |  | 		m_fFontSize, | 
					
						
							|  |  |  | 		L"en-us",                      // Local
 | 
					
						
							|  |  |  | 		&m_pTextFormat | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ASSERT(SUCCEEDED(hr), "Create IDWriteTextFormat Failed!"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | IDWriteTextFormat * e2d::EFont::_getTextFormat() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_bRecreateNeeded) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_initTextFormat(); | 
					
						
							|  |  |  | 		m_bRecreateNeeded = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return m_pTextFormat; | 
					
						
							|  |  |  | } |