JFontID JXFontManager::GetFontID ( const JCharacter* name, const JSize size, const JFontStyle& style ) const { const JSize count = itsFontList->GetElementCount(); for (JIndex i=1; i<=count; i++) { const FontInfo info = itsFontList->GetElement(i); if (*(info.name) == name && info.size == size && info.style.bold == style.bold && info.style.italic == style.italic) { return i; } } // falling through means we need to create a new entry JString xFontName, charSet; ConvertToXFontName(name, &xFontName, &charSet); #ifdef _J_USE_XFT FontInfo info; info.xftfont = GetNewFont(xFontName, charSet, size, style); info.exact = kJTrue; if (info.xftfont == NULL) { info.exact = kJFalse; info.xftfont = ApproximateFont(xFontName, charSet, size, style); } #else FontInfo info; info.xfont = GetNewFont(xFontName, charSet, size, style); info.exact = kJTrue; if (info.xfont == NULL) { info.exact = kJFalse; info.xfont = ApproximateFont(xFontName, charSet, size, style); } #endif info.name = new JString(name); assert( info.name != NULL ); info.size = size; info.style = style; itsFontList->AppendElement(info); return itsFontList->GetElementCount(); }
void JXFontManager::ApproximateFont ( const JCharacter* origName, const JSize origSize, const JFontStyle& origStyle, XFont* xfont ) const { JString name = origName; JSize size = origSize; JFontStyle style = origStyle; while (1) { if (size % 2 == 1) { size--; // even sizes are more common } else if (size < 12) { size += 2; } else if (size > 12) { size -= 2; } else if (style.bold) { style.bold = kJFalse; size = origSize; } else if (style.italic) { style.italic = kJFalse; size = origSize; } else if (name != JGetDefaultFontName()) { name = JGetDefaultFontName(); size = origSize; style = origStyle; } else { // this should never happen, but it does with some Win95 X servers cerr << "The X server does not have any 75 dpi PostScript fonts, not even "; cerr << JGetDefaultFontName() << endl; cerr << "Please install the xorg-x11-fonts-75dpi package" << endl; JXApplication::Abort(JXDocumentManager::kServerDead, kJFalse); } if (GetNewFont(name, size, style, xfont)) { break; } } }
static HFONT GetNewBrowserFont(HDC hDC, LPSTR pTypeFace, WORD wStyle, int size, BYTE bItalic, BYTE bUnderline, BYTE bVector) { if (!FontFace[0]) { WORD ylu = HIWORD(GetDialogBaseUnits()); KppGetKappaIniFile(return_buffer, RET_BUFFER_LEN); GetPrivateProfileString("Browser", "FontFace", "Default", FontFace, 32, return_buffer); FontSize = GetPrivateProfileInt("Browser", "FontSize", wStartFontSize, return_buffer); /* Get FontSize in points */ FontSize = (FontSize * ylu * 72) / (8 * wLogPixelY); bDefaultFont = !strcmpi(FontFace, "Default"); } if (bDefaultFont) strcpy(FontFace, pTypeFace); else if (size == (int) wStartFontSize) size = FontSize; if (wStartFontSize != START_FONT_SIZE) size = MulDiv(size, wStartFontSize, START_FONT_SIZE); return GetNewFont(FontFace, wStyle, size, bItalic, bUnderline, bVector); }
JFontID JXFontManager::GetFontID ( const JCharacter* name, const JSize size, const JFontStyle& style ) const { const JSize count = itsFontList->GetElementCount(); for (JIndex i=1; i<=count; i++) { const FontInfo info = itsFontList->GetElement(i); if (*(info.name) == name && info.size == size && info.style.bold == style.bold && info.style.italic == style.italic) { return i; } } // falling through means we need to create a new entry const JString xFontName = ConvertToXFontName(name); FontInfo info; if (GetNewFont(xFontName, size, style, &(info.xfont))) { info.exact = kJTrue; } else { info.exact = kJFalse; ApproximateFont(xFontName, size, style, &(info.xfont)); } info.name = new JString(name); assert( info.name != NULL ); info.size = size; info.style = style; info.monoWidth = IsMonospace(info.xfont); itsFontList->AppendElement(info); return itsFontList->GetElementCount(); }
XFontStruct* #endif JXFontManager::ApproximateFont ( const JCharacter* origName, const JCharacter* origCharSet, const JSize origSize, const JFontStyle& origStyle ) const { JString name = origName; JString charSet = origCharSet; JSize size = origSize; JFontStyle style = origStyle; #ifdef _J_USE_XFT XftFont* xfont = NULL; #else XFontStruct* xfont = NULL; #endif while (xfont == NULL) { if (size % 2 == 1) { size--; // even sizes are more common } else if (size < 12) { size += 2; } else if (size > 12) { size -= 2; } else if (style.bold) { style.bold = kJFalse; size = origSize; } else if (style.italic) { style.italic = kJFalse; size = origSize; } else if (name != JGetDefaultFontName()) { name = JGetDefaultFontName(); size = origSize; style = origStyle; } else if (!charSet.IsEmpty()) { charSet.Clear(); name = origName; size = origSize; style = origStyle; } else { // this should never happen, but it does with some Win95 X servers cerr << "The X server does not have any PostScript fonts at all, not even "; cerr << JGetDefaultFontName() << endl; JXApplication::Abort(JXDocumentManager::kServerDead, kJFalse); } xfont = GetNewFont(name, charSet, size, style); } return xfont; }