Beispiel #1
0
CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
  return GetNativeFont(GetNativeCharSet(), pLogFont);
#else
  return CFX_ByteString();
#endif
}
CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset)
{
	//searching native font is slow, so we must save time
	for (int32_t i=0,sz=m_aNativeFont.GetSize(); i<sz; i++)
	{
		if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i))
		{
			if (pData->nCharset == nCharset)
				return pData->sFontName;
		}
	}

	CFX_ByteString sNew = GetNativeFont(nCharset);

	if (!sNew.IsEmpty())
	{
		CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
		pNewData->nCharset = nCharset;
		pNewData->sFontName = sNew;

		m_aNativeFont.Add(pNewData);
	}

	return sNew;
}
CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, uint8_t nCharset)
{
	if (!pDoc) return NULL;

	if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset);
	if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset();

	if (m_pSystemHandler)
		return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCharset);

	return NULL;
}
CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet,
                                         CPDF_Document* pDocument) {
  if (!pDocument)
    return nullptr;

#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
  LOGFONTA lf;
  CFX_ByteString csFontName = GetNativeFont(charSet, &lf);
  if (!csFontName.IsEmpty()) {
    if (csFontName == "Helvetica")
      return AddStandardFont(pDocument, csFontName);
    return pDocument->AddWindowsFont(&lf, false, true);
  }
#endif
  return nullptr;
}
Beispiel #5
0
// --------------------------------------------------------------
void
GFontWin32GDIPlus::GetExtent( const char * str, int inCharCount, float * outWidth, 
					   float * outHeight, VGDevice * context ) const 
{
	if (!inCharCount) {
		*outWidth = *outHeight = 0;
		return;
	}
	// convert input string
	DWORD count = (DWORD)mbstowcs(NULL, str, inCharCount);
	WCHAR * wstr = (WCHAR*) malloc ((count + 1) * sizeof(WCHAR));
	mbstowcs(wstr, str, inCharCount);

	//std::string s(str);
	//std::wstring wstr(s.length(),L' ');
	//std::copy(s.begin(), s.end(), wstr.begin());

	Graphics* gdiContext = (Graphics*) GetContext( context );

/*	-- known Gdi+ issue: 
	We must use the following way to determine correct font extent 
	because typical Graphics::MeasureString() method doesn't work
	properly (return values are incorrect due to antialiasing)
*/
	Font* dgiFont = GetNativeFont();

	// Layout rectangles used for drawing strings
	RectF   layoutRect_A(0.0f, 0.0f, 1300.0f, 1300.0f);
	// 1 range of character positions within the string
	CharacterRange charRange(0, inCharCount);
	// String format used to apply to string when drawing
	StringFormat strFormat;
	// Set three ranges of character positions.
	strFormat.SetMeasurableCharacterRanges(1, &charRange);
	Region *pCharRangeRegions = new Region();

	// Get the regions that correspond to the ranges within the string when
	// layout rectangle A is used. 
	gdiContext->MeasureCharacterRanges( wstr, inCharCount, dgiFont, layoutRect_A, &strFormat, 1, pCharRangeRegions);

	RectF boundRect;
	pCharRangeRegions->GetBounds( &boundRect, gdiContext);

	*outWidth = boundRect.Width;
	*outHeight = boundRect.Height;
	free (wstr);
}
Beispiel #6
0
CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet,
                                         const CPDF_Document* pDocument) {
  if (pDocument == NULL) {
    return NULL;
  }
  CPDF_Font* pFont = NULL;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
  LOGFONTA lf;
  CFX_ByteString csFontName = GetNativeFont(charSet, &lf);
  if (!csFontName.IsEmpty()) {
    if (csFontName == "Helvetica") {
      pFont = AddStandardFont(pDocument, csFontName);
    } else {
      pFont = ((CPDF_Document*)pDocument)->AddWindowsFont(&lf, FALSE, TRUE);
    }
  }
#endif
  return pFont;
}
Beispiel #7
0
// --------------------------------------------------------------
void	
GFontWin32GDIPlus::GetExtent( unsigned char c, float * outWidth, 
					          float * outHeight, VGDevice * context ) const
{
	WCHAR wstr [] = L"0";
	mbstowcs(wstr, (const char*)&c, 1);

	Graphics* gdiContext = (Graphics*) GetContext( context );

/*	-- known Gdi+ issue: 
	We must use the following way to determine correct font extent 
	because typical Graphics::MeasureString() method doesn't work
	properly (return values are incorrect due to antialiasing)
*/
	Font* dgiFont = GetNativeFont();

	// Layout rectangles used for drawing strings
	RectF   layoutRect_A(0.0f, 0.0f, 1300.0f, 1300.0f);
	// 1 range of character positions within the string
	CharacterRange charRange(0, 1);
	// String format used to apply to string when drawing
	StringFormat strFormat;
	// Set three ranges of character positions.
	strFormat.SetMeasurableCharacterRanges(1, &charRange);
	Region *pCharRangeRegions = new Region();

	// Get the regions that correspond to the ranges within the string when
	// layout rectangle A is used. 
	gdiContext->MeasureCharacterRanges( wstr, 1, dgiFont, layoutRect_A, &strFormat, 1, pCharRangeRegions);

	RectF boundRect;
	pCharRangeRegions->GetBounds( &boundRect, gdiContext);

	*outHeight = boundRect.Height;
	*outWidth = boundRect.Width;
	// in some cases (when some symbols must be forced into char map), extent needs to be fixed  
	if (c == 139) *outWidth = 6.0;

}
Beispiel #8
0
// --------------------------------------------------------------
GFontWin32GDIPlus::~GFontWin32GDIPlus()
{ 
	Font* winFont = GetNativeFont();
	if( winFont )
		delete ( winFont );
}