/*
* testICU
*
* Authors:
* fred
* bulia byak <buliabyak@users.sf.net>
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef PANGO_ENABLE_ENGINE
#define PANGO_ENABLE_ENGINE
#endif
#include <pango/pangoft2.h>
#include <pango/pango-ot.h>
#include "libnrtype/FontFactory.h"
#include "libnrtype/font-instance.h"
#include "util/unordered-containers.h"
#include <map>
typedef INK_UNORDERED_MAP<PangoFontDescription*, font_instance*, font_descr_hash, font_descr_equal> FaceMapType;
// need to avoid using the size field
int h = 0;
h *= 1128467;
h += (int)pango_font_description_get_style(x);
h *= 1128467;
h += (int)pango_font_description_get_variant(x);
h *= 1128467;
h += (int)pango_font_description_get_weight(x);
h *= 1128467;
h += (int)pango_font_description_get_stretch(x);
return h;
}
bool font_descr_equal::operator()( PangoFontDescription *const&a, PangoFontDescription *const &b) const {
//if ( pango_font_description_equal(a,b) ) return true;
if ( pango_font_description_get_style(a) != pango_font_description_get_style(b) ) return false;
if ( pango_font_description_get_variant(a) != pango_font_description_get_variant(b) ) return false;
if ( pango_font_description_get_weight(a) != pango_font_description_get_weight(b) ) return false;
if ( pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b) ) return false;
return true;
}
/////////////////// helper functions
static void noop(...) {}
//#define PANGO_DEBUG g_print
///////////////////// FontFactory
#ifndef USE_PANGO_WIN32
// the substitute function to tell fontconfig to enforce outline fonts
{
//char *fam = NULL;
//FcPatternGetString(pattern, "FC_FAMILY",0, &fam);
//printf("subst_f on %s\n",fam);
}
#endif
{
return lUsine;
}
nbEnt(0), // Note: this "ents" cache only keeps fonts from being unreffed, does not speed up access
maxEnt(32),
#ifdef USE_PANGO_WIN32
#else
fontContext(0),
#endif
fontSize(512),
loadedPtr(new FaceMapType())
{
// std::cout << pango_version_string() << std::endl;
#ifdef USE_PANGO_WIN32
#else
72, 72);
this,
NULL);
#endif
}
font_factory::~font_factory(void)
{
#ifdef USE_PANGO_WIN32
#else
//pango_ft2_shutdown_display();
#endif
//g_object_unref(fontContext);
if (loadedPtr) {
delete tmp;
loadedPtr = 0;
}
}
{
if (font) {
// Once the format for the font specification is decided, it must be
// kept.. if it is absolutely necessary to change it, the attribute
// it is written to needs to have a new version so the legacy files
// can be read.
copyAsString = 0;
}
return pangoString;
}
{
if (font) {
}
return pangoString;
}
/*
* Wrap calls to pango_font_description_get_family
* and replace some of the pango font names with generic css names
* http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#generic-font-families
*
* This function should be called in place of pango_font_description_get_family()
*/
if (fontNameMap.empty()) {
}
}
return pangoFamily;
}
{
if (fontDescr) {
// For now, keep it as family name taken from pango
if( pangoFamily ) {
}
}
return family;
}
{
if (fontDescr) {
// For now, keep it as style name taken from pango
fontDescrAsString = 0;
}
return style;
}
/////
// Calculate a Style "value" based on CSS values for ordering styles.
{
int value =
return value;
}
// Determines order in which styles are presented (sorted by CSS style values)
//static bool StyleNameCompareInternal(const StyleNames &style1, const StyleNames &style2)
//{
// return( StyleNameValue( style1.CssName ) < StyleNameValue( style2.CssName ) );
//}
{
}
static bool ustringPairSort(std::pair<PangoFontFamily*, Glib::ustring> const& first, std::pair<PangoFontFamily*, Glib::ustring> const& second)
{
// well, this looks weird.
}
{
// Gather the family names as listed by Pango
int numFamilies = 0;
// not size_t
continue;
}
}
}
}
{
// Gather the styles for this family
int numFaces = 0;
// If the face has a name, describe it, and then use the
// description to get the UI family and face strings
// std::cout << "Display Name: " << displayName << std::endl;
continue;
}
if (faceDescr) {
// std::cout << familyUIName << " " << styleUIName << " " << displayName << std::endl;
// Disable synthesized (faux) font faces except for CSS generic faces
continue;
}
}
// Pango breaks the 1 to 1 mapping between Pango weights and CSS weights by
// adding Semi-Light (as of 1.36.7), Book (as of 1.24), and Ultra-Heavy (as of
// 1.24). We need to map these weights to CSS weights. Book and Ultra-Heavy
// are rarely used. Semi-Light (350) is problematic as it is halfway between
// Light (300) and Normal (400) and if care is not taken it is converted to
// Normal, rather than Light.
//
// Note: The ultimate solution to handling various weight in the same
// font family is to support the @font rules from CSS.
//
// Additional notes, helpful for debugging:
// Pango's FC backend:
// Weights defined in fontconfig/fontconfig.h
// String equivalents in src/fcfreetype.c
// Weight set from os2->usWeightClass
// Use Fontforge: Element->Font Info...->OS/2->Misc->Weight Class to check font weight
}
}
}
bool exists = false;
exists = true;
break;
}
}
// Add the style information
}
}
}
// Sort the style lists
return ret;
}
{
if (style) {
// First try to use the font specification if it is set
}
// If that failed, try using the CSS information in the style
if (!font) {
// This duplicates Layout::EnumConversionItem... perhaps we can share code?
case SP_CSS_FONT_STYLE_ITALIC:
break;
break;
case SP_CSS_FONT_STYLE_NORMAL:
default:
break;
}
case SP_CSS_FONT_WEIGHT_100:
break;
case SP_CSS_FONT_WEIGHT_200:
break;
case SP_CSS_FONT_WEIGHT_300:
break;
case SP_CSS_FONT_WEIGHT_400:
break;
case SP_CSS_FONT_WEIGHT_500:
break;
case SP_CSS_FONT_WEIGHT_600:
break;
case SP_CSS_FONT_WEIGHT_700:
case SP_CSS_FONT_WEIGHT_BOLD:
break;
case SP_CSS_FONT_WEIGHT_800:
break;
case SP_CSS_FONT_WEIGHT_900:
break;
default:
g_warning("FaceFromStyle: Unrecognized font_weight.computed value");
break;
}
// PANGO_WIEGHT_ULTRAHEAVY not used (not CSS2)
break;
break;
break;
break;
break;
break;
break;
break;
default:
g_warning("FaceFromStyle: Unrecognized font_stretch.computed value");
break;
}
break;
default:
break;
}
}
}
return font;
}
{
return res;
}
{
if (pangoString) {
// Create a font description from the string - this may fail or
// produce unexpected results if the string does not have a good format
if (descr) {
}
}
}
return fontInstance;
}
{
if (fontSpecification) {
// How the string is used to reconstruct a font depends on how it
// was constructed in ConstructFontSpecification. As it stands,
// the font specification is a pango-created string
}
return font;
}
<< ((char)((*tag & 0x000000ff)>>0))
}
return tag_name;
}
{
#ifdef USE_PANGO_WIN32
// damn Pango fudges the size, so we need to unfudge. See source of pango_win32_font_map_init()
pango_font_description_set_size(descr, (int) (fontSize*PANGO_SCALE*72/GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY))); // mandatory huge size (hinting workaround)
#else
pango_font_description_set_size(descr, (int) (fontSize*PANGO_SCALE)); // mandatory huge size (hinting workaround)
#endif
// not yet loaded
// workaround for bug #1025565.
// fonts without families blow up Pango.
}
else {
}
if ( nFace ) {
// duplicate FcPattern, the hard way
res = new font_instance();
// store the descr of the font we asked for, since this is the key where we intend
// to put the font_instance at in the unordered_map. the descr of the returned
// pangofont may differ from what was asked, so we don't know (at this
// point) whether loadedFaces[that_descr] is free or not (and overwriting
// an entry will bring deallocation problems)
// failed to install face -> bitmap font
// printf("face failed\n");
delete res;
if ( canFail ) {
}
} else {
}
} else {
// no match
if ( canFail ) {
PANGO_DEBUG("falling back to 'sans-serif'\n");
}
}
// Extract which OpenType tables are in the font. We'll make a list of all tables
// regardless of which script and langauge they are in. These functions are deprecated but
// will eventually be replaced by newer functions (according to Behdad).
// std::cout << " scripts: " << std::endl;
for( unsigned i = 0; scripts[i] != 0; ++i ) {
// dump_tag( &scripts[i], " " );
// if( languages[0] != 0 )
// std::cout << " languages: " << std::endl;
for( unsigned j = 0; languages[j] != 0; ++j ) {
// dump_tag( &languages[j], " lang: ");
if( pango_ot_info_find_language(info, PANGO_OT_TABLE_GSUB, script_index, languages[j], &language_index, NULL)) {
if( features[0] != 0 )
// std::cout << " features: " << std::endl;
for( unsigned k = 0; features[k] != 0; ++k ) {
// dump_tag( &features[k], " feature: ");
}
} else {
// std::cout << " No languages defined" << std::endl;
// if( features[0] != 0 )
// std::cout << " default features: " << std::endl;
for( unsigned k = 0; features[k] != 0; ++k ) {
// dump_tag( &features[k], " feature: " );
}
}
}
} else {
// std::cout << " No scripts defined! " << std::endl;
}
}
// if( features[0] != 0 )
// std::cout << " DFTL DFTL features: " << std::endl;
for( unsigned i = 0; features[i] != 0; ++i ) {
// dump_tag( &features[i], " feature: " );
}
// std::map<Glib::ustring,int>::iterator it;
// for( it = res->openTypeTables.begin(); it != res->openTypeTables.end(); ++it) {
// std::cout << "Table: " << it->first << " Occurances: " << it->second << std::endl;
// }
} else {
// already here
}
if (res) {
res->InitTheFace();
}
return res;
}
font_instance *font_factory::Face(char const *family, int variant, int style, int weight, int stretch, int /*size*/, int /*spacing*/)
{
return res;
}
{
if ( who ) {
// not found
} else {
// printf("unrefFace %p: success\n",who);
}
}
}
{
for (int i = 0;i < nbEnt;i++) {
// printf("present\n");
return;
}
}
printf("cache sur-plein?\n");
return;
}
int bi = 0;
for (int i = 1;i < nbEnt;i++) {
bi = i;
}
}
}
nbEnt++;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :