CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const FX_WCHAR* pszFontFamily,
                                      uint32_t dwFontStyles,
                                      uint16_t wCodePage) {
  uint32_t dwHash =
      FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage);
  CFGAS_GEFont* pFont = nullptr;
  if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont))
    return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr;
  FX_FONTDESCRIPTOR const* pFD =
      FindFont(pszFontFamily, dwFontStyles, true, wCodePage);
  if (!pFD)
    pFD = FindFont(pszFontFamily, dwFontStyles, false, wCodePage);
  if (!pFD)
    return nullptr;

  if (wCodePage == 0xFFFF)
    wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet);
  pFont =
      CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this);
  if (!pFont)
    return nullptr;

  m_Fonts.Add(pFont);
  m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
  dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
  m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
  return LoadFont(pFont, dwFontStyles, wCodePage);
}
CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage(
    uint16_t wCodePage,
    uint32_t dwFontStyles,
    const FX_WCHAR* pszFontFamily) {
  uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
  CFGAS_GEFont* pFont = nullptr;
  if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
    return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr;
  }
  FX_FONTDESCRIPTOR const* pFD =
      FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage);
  if (!pFD)
    pFD = FindFont(nullptr, dwFontStyles, TRUE, wCodePage);
  if (!pFD)
    pFD = FindFont(nullptr, dwFontStyles, FALSE, wCodePage);
  if (!pFD)
    return nullptr;

  pFont =
      CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this);
  if (pFont) {
    m_Fonts.Add(pFont);
    m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
    dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage);
    m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
    return LoadFont(pFont, dwFontStyles, wCodePage);
  }
  return nullptr;
}
int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, int32_t nCharset, FX_BOOL bFind)
{
	int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
	if (nFontIndex >= 0) return nFontIndex;

//	nFontIndex = FindFont("", nCharset);
//	if (nFontIndex >= 0) return nFontIndex;

	CFX_ByteString sAlias;
	CPDF_Font* pFont = NULL;

	if (bFind)
		pFont = FindFontSameCharset(sAlias, nCharset);

	if (!pFont)
	{
		CFX_ByteString sTemp = sFontName;
		pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);

		/*
		if (FindFont(sAlias))
		{
			sAlias = EncodeFontAlias(sTemp, nCharset);
		}
		else
		*/
		{
			sAlias = EncodeFontAlias(sTemp, nCharset);
		}
	}

	AddedFont(pFont, sAlias);

	return AddFontData(pFont, sAlias, nCharset);
}
Exemple #4
0
/* SetListFlags()
 * =======================================================================
 * Sets the AFLAGS and SFLAGS of the bitlist if the device fonts
 * match.
 * 
 * We take the fonts allocated to the device and find them in
 * the main font list. If found, we unlink it from the linked list.
 */
void
SetListFlags( void )
{
   FON_PTR font;
   FON_PTR xfont;
   int     index;
      
   for( index = 0; index < DFCOUNT( cur_device ); index++ )
   {
       font = DFONT( cur_device )[ index ];
       xfont = FindFont( font );

       if( xfont )
       {
         if( xfont == bit_list )
             bit_list = FNEXT( xfont );
         
         if( xfont == bit_last )
             bit_last = FPREV( xfont );
                 
         if( FPREV( xfont ) )
         {
           FNEXT( FPREV( xfont ) ) = FNEXT( xfont );
         }
       
         if( FNEXT( xfont ) )
         {
           FPREV( FNEXT( xfont ) ) = FPREV( xfont );
         }
       }             
   }
}
void* CFX_LinuxFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, const FX_CHAR* cstr_face, FX_BOOL& bExact)
{
    CFX_ByteString face = cstr_face;
    int iBaseFont;
    for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++)
        if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
            face = Base14Substs[iBaseFont].m_pSubstName;
            bExact = TRUE;
            break;
        }
    if (iBaseFont < 12) {
        return GetFont(face);
    }
    void* p = NULL;
    FX_BOOL bCJK = TRUE;
    switch (charset) {
        case FXFONT_SHIFTJIS_CHARSET: {
                int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family);
                if (index < 0) {
                    break;
                }
                for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++)
                    if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p)) {
                        return p;
                    }
            }
            break;
        case FXFONT_GB2312_CHARSET: {
                static int32_t s_gbCount = sizeof(g_LinuxGbFontList) / sizeof(const FX_CHAR*);
                for (int32_t i = 0; i < s_gbCount; i++)
                    if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) {
                        return p;
                    }
            }
            break;
        case FXFONT_CHINESEBIG5_CHARSET: {
                static int32_t s_b5Count = sizeof(g_LinuxB5FontList) / sizeof(const FX_CHAR*);
                for (int32_t i = 0; i < s_b5Count; i++)
                    if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) {
                        return p;
                    }
            }
            break;
        case FXFONT_HANGEUL_CHARSET: {
                static int32_t s_hgCount = sizeof(g_LinuxHGFontList) / sizeof(const FX_CHAR*);
                for (int32_t i = 0; i < s_hgCount; i++)
                    if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) {
                        return p;
                    }
            }
            break;
        default:
            bCJK = FALSE;
            break;
    }
    if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
        return GetFont("Courier New");
    }
    return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
}
Exemple #6
0
myinline const BFont ArpMessage::GetFont(const char *name, const BFont& def, int32 index) const
{
	if( this ) {
		BFont res;
		if( FindFont(name, index, &res) != B_NO_ERROR ) return def;
		return res;
	}
	return def;
}
Exemple #7
0
cgSizeF cgGdiplusRender::GetUICharSize( TCHAR ch, cgID idFont )
{
	Gdiplus::Font * pkFont = FindFont(idFont);
	if (pkFont)
	{
		int w = ch<128?pkFont->GetSize()/2:pkFont->GetSize();
		return cgSizeF(w, pkFont->GetSize());
	}
	return cgSizeF();
}
Exemple #8
0
void ResetFonts()
{
	fontCount = 0;

	CFont *f;
	// hardcoded font fot "conchars" - uses different shader flags, plus different texture location
	f = gl_concharsFont = &fontArray[fontCount++];
	f->Name         = "conchars";
	f->shader       = FindShader("pics/conchars", SHADER_ALPHA);
	f->firstChar    = 0;
	f->charWidth    = 8;
	f->charHeight   = 8;
	f->outWidth     = 8;
	f->outHeight    = 8;
	f->spacing      = 0;
	// load other fonts
	gl_debugFont   = FindFont("debug");
	gl_consoleFont = FindFont("console");
}
Exemple #9
0
void* CFX_LinuxFontInfo::MapFont(int weight,
                                 FX_BOOL bItalic,
                                 int charset,
                                 int pitch_family,
                                 const FX_CHAR* cstr_face,
                                 int& iExact) {
  void* font = GetSubstFont(cstr_face);
  if (font) {
    iExact = 1;
    return font;
  }
  FX_BOOL bCJK = TRUE;
  switch (charset) {
    case FXFONT_SHIFTJIS_CHARSET: {
      int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family);
      if (index < 0) {
        break;
      }
      for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) {
        auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]);
        if (it != m_FontList.end()) {
          return it->second;
        }
      }
    } break;
    case FXFONT_GB2312_CHARSET: {
      for (size_t i = 0; i < FX_ArraySize(g_LinuxGbFontList); ++i) {
        auto it = m_FontList.find(g_LinuxGbFontList[i]);
        if (it != m_FontList.end()) {
          return it->second;
        }
      }
    } break;
    case FXFONT_CHINESEBIG5_CHARSET: {
      for (size_t i = 0; i < FX_ArraySize(g_LinuxB5FontList); ++i) {
        auto it = m_FontList.find(g_LinuxB5FontList[i]);
        if (it != m_FontList.end()) {
          return it->second;
        }
      }
    } break;
    case FXFONT_HANGEUL_CHARSET: {
      for (size_t i = 0; i < FX_ArraySize(g_LinuxHGFontList); ++i) {
        auto it = m_FontList.find(g_LinuxHGFontList[i]);
        if (it != m_FontList.end()) {
          return it->second;
        }
      }
    } break;
    default:
      bCJK = FALSE;
      break;
  }
  return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
}
void CPDF_StreamContentParser::Handle_SetFont() {
  FX_FLOAT fs = GetNumber(0);
  if (fs == 0) {
    fs = m_DefFontSize;
  }
  m_pCurStates->m_TextState.GetModify()->m_FontSize = fs;
  CPDF_Font* pFont = FindFont(GetString(1));
  if (pFont) {
    m_pCurStates->m_TextState.SetFont(pFont);
  }
}
Exemple #11
0
ID3DXFont *Fonts::GetFont(int fontSize,IDirect3DDevice9 *dev){
	font *f = FindFont(fontSize);
	if(!f){
		font newFont = {0};
		newFont.fontSize = fontSize;
		if(FAILED(D3DXCreateFontA(dev,fontSize,0,FW_NORMAL,0,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH | FF_DONTCARE,"Arial",&newFont.font)))
			return NULL;
		fonts.push_back(newFont);
		return newFont.font;
	}
	return f->font;
}
CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode(
    FX_WCHAR wUnicode,
    uint32_t dwFontStyles,
    const FX_WCHAR* pszFontFamily) {
  const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode);
  if (pRet->wBitField == 999)
    return nullptr;

  uint32_t dwHash =
      FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField);
  CFGAS_GEFont* pFont = nullptr;
  if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont))
    return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr;

  FX_FONTDESCRIPTOR const* pFD =
      FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage,
               pRet->wBitField, wUnicode);
  if (!pFD && pszFontFamily) {
    pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage,
                   pRet->wBitField, wUnicode);
  }
  if (!pFD)
    return nullptr;

  uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet);
  const FX_WCHAR* pFontFace = pFD->wsFontFace;
  pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this);
  if (pFont) {
    m_Fonts.Add(pFont);
    m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
    dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
    m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
    dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage);
    m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
    return LoadFont(pFont, dwFontStyles, wCodePage);
  }
  return nullptr;
}
Exemple #13
0
void cgGdiplusRender::DrawUIText( LPCTSTR lpctText, int nTextLen, 
	int x, int y, cgID font, cgColor color )
{
	Gdiplus::Font * pkFont = FindFont(font);
	Gdiplus::SolidBrush brush(Gdiplus::Color((Gdiplus::ARGB)color));
	Gdiplus::PointF point(x, y);

//	m_pkGraphics->DrawString(lpctText, nTextLen, pkFont, point, &brush);

	for (int i = 0; i < nTextLen; ++i)
	{
		m_pkGraphics->DrawString(lpctText+i, 1, pkFont, point, &brush);
		point.X += GetUICharWidth(lpctText[i], font);
	}
}
Exemple #14
0
int cgGdiplusRender::GetUICharWidth( TCHAR ch, cgID idFont )
{
	int nW = 0;
	Gdiplus::Font * pkFont = FindFont(idFont);
	if (pkFont)
	{
		int nSize = pkFont->GetSize(); 

		if (ch < 128)
			nW = nSize/2;
		else
			nW = nSize;
	}
	return nW;
}
Exemple #15
0
EXPORT_C TBool CTypefaceStore::IncrementFontCount(const CFont* aFont)
/**
Search for the font in iFontAccess and increment its count.
@param aFont Font to search for.
@return ETrue if the specified font is found, EFalse otherwise.
*/
	{
	TInt idx = 0;
	if (FindFont(aFont, idx))
		{
		iFontAccess->At(idx).iAccessCount++;
		return ETrue;
		}
	return EFalse;
	}
//-----------------------------------------------------------------------------
CPUTFont *CPUTAssetLibrary::GetFont(const cString &name )
{
    // Resolve name to absolute path
    cString absolutePathAndFilename;
    CPUTFileSystem::ResolveAbsolutePathAndFilename( (mFontDirectoryName + name), &absolutePathAndFilename);

    // If we already have one by this name, then return it
    CPUTFont *pFont = FindFont(absolutePathAndFilename, true);
    if(NULL==pFont)
    {
        return CPUTFont::CreateFont( name, absolutePathAndFilename);
    }
    pFont->AddRef();
    return pFont;
}
Exemple #17
0
/*
LPCTSTR FreeTypeFontEngine::GetFontById(int faceid, int& weight, bool& italic)
{
	CCriticalSectionLock __lock;

	FreeTypeFontInfo** pp	= m_arrFontList.Begin();
	FreeTypeFontInfo** end	= m_arrFontList.End();
	for(; pp != end; ++pp) {
		FreeTypeFontInfo* p = *pp;
		if (p->GetId() == faceid) {
			p->SetMruCounter(this);
			weight = p->GetWeight();
			italic = p->IsItalic();
			return p->GetName();
		}
	}
	return NULL;
}
*/
FreeTypeFontInfo* FreeTypeFontEngine::FindFont(void* lpparams)
{
	FREETYPE_PARAMS* params = (FREETYPE_PARAMS*)lpparams;
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTMAP);
	FullNameMap::const_iterator iter=m_mfullMap.find(params->strFullName);
	if (iter!=m_mfullMap.end())
	{
		FreeTypeFontInfo* p = iter->second;
		if (p->GetFullName()!=params->strFullName)	//属于替换字体
			return FindFont(params->lplf->lfFaceName, params->lplf->lfWeight, !!params->lplf->lfItalic);
		p->SetMruCounter(this);
		return p;
	}
	//m_bAddOnFind = true;
	return AddFont(params);
}
Exemple #18
0
void cgGdiplusRender::DrawUIText( LPCTSTR lpctText, int nTextLen, 
	const cgRectF& rect, cgID font, int space , cgColor color, int style )
{
	Gdiplus::RectF kDrawRect (rect.x, rect.y, rect.w, rect.h);
	Gdiplus::StringFormat kFormat;

	if (style&DT_CENTER)
		kFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	if (style&DT_VCENTER)
		kFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	Gdiplus::Font * pkFont = FindFont(font);
	Gdiplus::SolidBrush brush(Gdiplus::Color((Gdiplus::ARGB)color));

	m_pkGraphics->DrawString(lpctText, nTextLen, pkFont,  kDrawRect, 
		&kFormat, &brush);
}
//-----------------------------------------------------------------------------
CPUTFont *CPUTAssetLibrary::GetFont(const std::string &name )
{
    // Resolve name to absolute path
    std::string absolutePathAndFilename;
    CPUTFileSystem::ResolveAbsolutePathAndFilename( (mFontDirectoryName + name), &absolutePathAndFilename);

    // If we already have one by this name, then return it
    CPUTFont *pFont = FindFont(absolutePathAndFilename, true);
    if(NULL==pFont)
    {
        CPUTFont *pFont = CPUTFont::Create( name, absolutePathAndFilename);
        LIBRARY_ASSERT(pFont, "Could not create font " + absolutePathAndFilename);
        if (pFont != NULL)
        AddFont(name, "", "", pFont);
        return pFont; 
    }
    pFont->AddRef();
    return pFont;
}
Exemple #20
0
BOOL FreeTypeFontEngine::RemoveFont(LPCWSTR FontName)
{
	if (!FontName) return false;
	LOGFONTW* fontarray = GetFontNameFromFile(FontName);
	LOGFONTW* c_fontarray = fontarray;	//记录原始指针
	if (!fontarray) return false;
	FTC_FaceID fid = NULL;
	BOOL bIsFontLoaded, bIsFontFileLoaded = false;
	COwnedCriticalSectionLock __lock2(2, COwnedCriticalSectionLock::OCS_DC);	//获取所有权,现在要处理DC,禁止所有绘图函数访问
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_MANAGER);
	while (*(char*)fontarray)
	{
		bIsFontLoaded = false;
		FreeTypeFontInfo* result = FindFont(fontarray->lfFaceName, fontarray->lfWeight, !!fontarray->lfItalic, false, &bIsFontLoaded);
		if (result)
		{
			fid = (FTC_FaceID)result->GetId();
			if (bIsFontLoaded)	//该字体已经被使用过
			{
				RemoveFont(result);	//枚举字体信息全部删除
				bIsFontFileLoaded = true;	//设置字体文件也被使用过
			}
			else
				RemoveThisFont(result, fontarray);
			CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTENG);
			FTC_Manager_RemoveFaceID(cache_man, fid);
			m_mfontList[(int)fid-1]=NULL;
		}
		fontarray++;
	}
	free(c_fontarray); //利用原始指针释放
	if (bIsFontFileLoaded)	//若字体文件被使用过,则需要清楚所有DC
	{
		CTLSDCArray::iterator iter = TLSDCArray.begin();
		while (iter!=TLSDCArray.end())
		{
			((CBitmapCache*)*iter)->~CBitmapCache();	//清除掉所有使用中的DC
			++iter;
		}
	}
	return true;
}
Exemple #21
0
EXPORT_C void CTypefaceStore::ReleaseFont(CFont* aFont)
/** Releases the hold of a typeface store client on a specified font.

Decrements the access-count for the specified font by one. If this reduces the access-count 
to zero then the font is no longer needed by any client, and is deleted from 
the typeface store list.

@param aFont The font to be released by the client. */
	{
	
	TEXTBASE_ASSERT_DEBUG_GENERAL(NULL != iFontAccess, User::Panic(KCTypefaceStore, KErrNoMemory));
	if (!aFont)
		return;
	TInt idx = 0;
	TEXTBASE_ASSERT_ALWAYS_GENERAL(FindFont(aFont, idx), User::Panic(KCTypefaceStore, KErrNotFound));
	TEXTBASE_ASSERT_DEBUG_GENERAL(0 < iFontAccess->At(idx).iAccessCount, User::Panic(KCTypefaceStore, KErrCorrupt));
	iFontAccess->At(idx).iAccessCount--;
	if (0 == iFontAccess->At(idx).iAccessCount)
		{
		CFont *font=iFontAccess->At(idx).iFont;
		iFontAccess->Delete(idx);
		delete font;
		}
	}
Exemple #22
0
void CHudCloseCaption::DrawStream( wrect_t &rcText, const CCloseCaptionPhrase *phrase )
{
    vgui::surface()->DrawSetColor( GetBgColor() );
    vgui::surface()->DrawFilledRect( rcText.left, rcText.top, rcText.right, rcText.bottom );

    int c = phrase->CountTokens();
    int i;

    int fontheight = vgui::surface()->GetFontTall( fontSet[ FONT_NORMAL ] );
    int x = 0;
    int y = 0;

    int available_width = rcText.right - rcText.left;

    color32 clr;
    clr.r = 255;
    clr.b = 255;
    clr.g = 255;
    clr.a = 255;

    CUtlVector< color32 > colorStack;
    colorStack.AddToTail( clr );

    int italic = 0;
    int bold = 0;

    for ( i = 0; i < c; i++ )
    {
        const wchar_t *token = phrase->GetToken( i );
        if ( !token )
            continue;

        wchar_t cmd[ 256 ];
        wchar_t args[ 256 ];

        if ( phrase->SplitCommand( token, cmd, args ) )
        {
            if ( !wcscmp( cmd, L"cr" ) )
            {
                x = 0;
                y += ( fontheight + 1 );
            }

            if ( !wcscmp( cmd, L"clr" ) )
            {
                if ( args[0] == 0 && colorStack.Count()>= 2)
                {
                    colorStack.Remove( colorStack.Count() - 1 );
                }
                else
                {
                    int r, g, b;
                    color32 newcolor;
                    if ( 3 == swscanf( args, L"%i,%i,%i", &r, &g, &b ) )
                    {
                        newcolor.r = r;
                        newcolor.g = g;
                        newcolor.b = b;
                        newcolor.a = 255;
                        colorStack.AddToTail( newcolor );
                    }
                }
            }

            if ( !wcscmp( cmd, L"I" ) )
            {
                italic = !italic;
            }

            if ( !wcscmp( cmd, L"B" ) )
            {
                bold = !bold;
            }

            continue;
        }

        int w, h;

        if ( italic )
        {
            italic = FONT_ITALIC;
        }

        if ( bold )
        {
            bold = FONT_BOLD;
        }
        vgui::HFont useF = FindFont( bold | italic );

        wchar_t sz[ 1024 ];
        swprintf( sz, L"%s ", token );

        vgui::surface()->GetTextSize( useF, sz, w, h );

        if ( x + w > available_width )
        {
            x = 0;
            y += ( h + 1 );
        }

        wrect_t rcOut;
        rcOut.left = rcText.left + x + 5;
        rcOut.right = rcOut.left + w;
        rcOut.top = rcText.top + y;
        rcOut.bottom = rcOut.top + fontheight + 1;

        color32 useColor = colorStack[ colorStack.Count() - 1 ];

        vgui::surface()->DrawSetTextFont( useF );
        vgui::surface()->DrawSetTextPos( rcOut.left, rcOut.top );
        vgui::surface()->DrawSetTextColor( Color( useColor.r, useColor.g, useColor.b, useColor.a ) );
        vgui::surface()->DrawPrintText( sz, wcslen( sz ) );

        x += w;
    }
}
status_t
TerminalThemesAddon::ApplyThemeR5(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	status_t err;
	struct termprefs tp;
	
	err = MyMessage(theme, termpref);
	if (err)
		return err;
	tp.magic = TP_MAGIC;
	tp.version = TP_VERSION;
	tp.x = 0; // don't open at specific coords
	tp.y = 0;
	if (termpref.FindInt32(TP_COLS, (int32 *)&tp.p.cols) != B_OK)
		tp.p.cols = 80;
	if (termpref.FindInt32(TP_ROWS, (int32 *)&tp.p.rows) != B_OK)
		tp.p.rows = 25;
	if (termpref.FindInt32(TP_TABWIDTH, (int32 *)&tp.p.tab_width) != B_OK)
		tp.p.tab_width = 8;
	BFont tFont;
	tp.p.font_size = 12;
	strcpy(tp.p.font, "Courier10 BT/Roman");
	if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) {
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		strcpy(tp.p.font, ff);
		strcat(tp.p.font, "/");
		strcat(tp.p.font, fs);
		tp.p.font_size = (uint32)tFont.Size();
	}
	tp.p.cursor_blink_rate = 1000000;
	tp.p.refresh_rate = 0;
	
	if (FindRGBColor(termpref, TP_BG, 0, &tp.p.bg) != B_OK)
		tp.p.bg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_FG, 0, &tp.p.fg) != B_OK)
		tp.p.fg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_CURBG, 0, &tp.p.curbg) != B_OK)
		tp.p.curbg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_CURFG, 0, &tp.p.curfg) != B_OK)
		tp.p.curfg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELBG, 0, &tp.p.selbg) != B_OK)
		tp.p.selbg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELFG, 0, &tp.p.selfg) != B_OK)
		tp.p.selfg = make_color(255,255,255,255);
	
	if (termpref.FindInt32(TP_ENCODING, (int32 *)&tp.p.encoding) != B_OK)
		tp.p.encoding = 0; // UTF-8
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		BPath pTermPref;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK)
			return EINVAL;
		pTermPref.Append("Terminal");
		BFile fTermPref(pTermPref.Path(), B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE);
		if (fTermPref.InitCheck() != B_OK) {
			return fTermPref.InitCheck();
		}
		fTermPref.Write(&tp, sizeof(struct termprefs));
		BNodeInfo ni(&fTermPref);
		if (ni.InitCheck() == B_OK)
			ni.SetType("application/x-vnd.Be-pref");
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)((addr_t)teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kBeOSTerminalAppSig)) {
					err = B_OK;
					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", (int32)0);
					err = msgr.SendMessage(&msg);
				}
			}
		}
	}
	
	return B_OK;
}
Exemple #24
0
void CHudCloseCaption::ComputeStreamSize( int available_width, const CCloseCaptionPhrase *phrase, int& itemwidth, int& itemheight )
{
    int c = phrase->CountTokens();
    int i;

    int usedw = 0;
    int fontheight = vgui::surface()->GetFontTall( fontSet[ FONT_NORMAL ] );
    int height = fontheight+1;

    int italic = 0;
    int bold = 0;
    int maxwidth = 0;

    for ( i = 0; i < c; i++ )
    {
        const wchar_t *token = phrase->GetToken( i );
        if ( !token )
            continue;

        wchar_t cmd[ 256 ];
        wchar_t args[ 256 ];

        if ( phrase->SplitCommand( token, cmd, args ) )
        {
            if ( !wcscmp( cmd, L"cr" ) )
            {
                usedw = 0;
                height += ( fontheight + 1 );
            }

            if ( !wcscmp( cmd, L"I" ) )
            {
                italic = !italic;
            }

            if ( !wcscmp( cmd, L"B" ) )
            {
                bold = !bold;
            }

            continue;
        }

        if ( italic )
        {
            italic = FONT_ITALIC;
        }

        if ( bold )
        {
            bold = FONT_BOLD;
        }

        int w, h;

        vgui::HFont useF = FindFont( bold | italic );

        wchar_t sz[ 1024 ];
        swprintf( sz, L"%s ", token );

        vgui::surface()->GetTextSize( useF, sz, w, h );

        if ( usedw + w > available_width )
        {
            usedw = 0;
            height += ( h + 1 );
        }
        usedw += w;

        if ( usedw > maxwidth )
        {
            maxwidth = usedw;
        }
    }

    itemheight = height;
    itemwidth = maxwidth;
}
Exemple #25
0
int FreeTypeFontEngine::GetFontIdByName(LPCTSTR lpFaceName, int weight, bool italic)
{
	const FreeTypeFontInfo* pfi = FindFont(lpFaceName, weight, italic);
	return pfi ? pfi->GetId() : 0;
}
Exemple #26
0
FX_BOOL CPDF_InterForm::FindFormFont(const CPDF_Font* pFont,
                                     CFX_ByteString& csNameTag) {
  return FindFont(m_pFormDict, pFont, csNameTag);
}
Exemple #27
0
FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName,
                                     CPDF_Font*& pFont,
                                     CFX_ByteString& csNameTag) {
  return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag);
}
Exemple #28
0
status_t ArpMessage::FindFont(const char *name, BFont *font) const
{
	return FindFont(name,0,font);
}
Exemple #29
0
void
PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
{
	// try to convert from utf8 to MacRoman encoding schema...
	int32 srcLen  = size;
	int32 destLen = 1;
	char dest[3] = "\0\0";
	int32 state = 0;
	bool embed = true;
	font_encoding encoding = macroman_encoding;
	char fontName[B_FONT_FAMILY_LENGTH+B_FONT_STYLE_LENGTH+1];

	if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, utf8, &srcLen, dest, &destLen,
			&state, 0) != B_OK || dest[0] == 0) {
		// could not convert to MacRoman
		font_encoding fenc;
		uint16 index = 0;
		uint8 enc;

		GetFontName(&fState->beFont, fontName);
		embed = EmbedFont(fontName);

		REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode);
		if (find_encoding(unicode, enc, index)) {
			// is code point in the Adobe Glyph List?
			// Note if rendering the glyphs only would be desired, we could
			// always use the second method below (MakeUserDefinedEncoding),
			// but extracting text from the generated PDF would be almost
			// impossible (OCR!)
			REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc,
				(int)index);
			// use one of the user pre-defined encodings
			if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
				encoding = font_encoding(enc + tt_encoding0);
			} else {
				encoding = font_encoding(enc + t1_encoding0);
			}
			*dest = index;
		} else if (embed) {
			// if the font is embedded, create a user defined encoding at runtime
			uint8 index;
			MakeUserDefinedEncoding(unicode, enc, index);
			*dest = index;
			encoding = font_encoding(user_defined_encoding_start + enc);
		} else if (find_in_cid_tables(unicode, fenc, index, fFontSearchOrder)) {
			// font is not embedded use one of the CJK fonts for substitution
			REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index);
			dest[0] = unicode / 256;
			dest[1] = unicode % 256;
			destLen = 2;
			encoding = fenc;
			embed = false;
		} else {
			static bool found = false;
			REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode);
			if (!found) {
				found = true;
				REPORT(kError, fPage, "Could not find an encoding for character "
					"with unicode %d! Message is not repeated for other unicode "
					"values.", (int)unicode);
			}
			*dest = 0; // paint a box (is 0 a box in MacRoman) or
			return; // simply skip character
		}
	} else {
		REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen,
			destLen, (int)dest[0], (int)dest[1]);
	}

	// Note we have to build the user defined encoding before it is used in
	// PDF_find_font!
	if (!MakesPDF()) return;

	int		font;

	GetFontName(&fState->beFont, fontName, embed, encoding);
	font = FindFont(fontName, embed, encoding);
	if (font < 0) {
		REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default "
			"font", fontName);
		font = PDF_findfont(fPdf, "Helvetica", "macroman", 0);
	}

	fState->font = font;

	uint16 face = fState->beFont.Face();
	PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0
		? "true" : "false");
	PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0
		? "true" : "false");
	PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0);

	PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size()));

	const float x = tx(fState->penX);
	const float y = ty(fState->penY);
	const float rotation = fState->beFont.Rotation();
	const bool rotate = rotation != 0.0;

	if (rotate) {
		PDF_save(fPdf);
		PDF_translate(fPdf, x, y);
		PDF_rotate(fPdf, rotation);
	    PDF_set_text_pos(fPdf, 0, 0);
	} else
	    PDF_set_text_pos(fPdf, x, y);

	PDF_show2(fPdf, dest, destLen);

	if (rotate) {
		PDF_restore(fPdf);
	}
}
status_t
TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	BMessage lines;
	status_t err;
	int32 ival;
	rgb_color color;
	BString s;
	int i;

	err = MyMessage(theme, termpref);
	if (err)
		return err;

	for (i = 0; i < NENTS(sHaikuPrefsMapInt32); i++) {
		if (termpref.FindInt32(sHaikuPrefsMapInt32[i].name, &ival) < B_OK)
			ival = sHaikuPrefsMapInt32[i].def;
		s = "";
		s << ival;
		lines.AddString(sHaikuPrefsMapInt32[i].pref, s.String());
	}

	for (i = 0; i < NENTS(sHaikuPrefsMapColors); i++) {
		if (FindRGBColor(termpref, sHaikuPrefsMapColors[i].name, 0, &color) != B_OK)
			color = sHaikuPrefsMapColors[i].def;
		s = "";
		s << color.red << ", " << color.green << ", " << color.blue;
		lines.AddString(sHaikuPrefsMapColors[i].pref, s.String());
	}

	BFont tFont;
	for (i = 0; FindFont(termpref, TP_FONT, i, &tFont) == B_OK; i++) {
		// at least set the size
		s = "";
		s << (int32)tFont.Size();
		lines.AddString(PREF_HALF_FONT_SIZE, s.String());
		//tFont.PrintToStream();
		//printf("fixed: %d\n", tFont.IsFixed());
		//printf("f&h fixed: %d\n", tFont.IsFullAndHalfFixed());
		// don't even try to set the font if it's not there or not fixed
		if (!tFont.IsFixed() && !tFont.IsFullAndHalfFixed())
			continue;
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		s = "";
		s << ff;
		lines.AddString(PREF_HALF_FONT_FAMILY, s.String());
		s = "";
		s << fs;
		lines.AddString(PREF_HALF_FONT_STYLE, s.String());
	}

	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		SaveHaikuTerminalSettings(lines);
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)((addr_t)teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) {
					err = B_OK;
					//XXX: WRITEME
/*					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
*/
				}
			}
		}
	}
	
	return B_OK;
}