bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font)
{
    if (fontString.isEmpty())
        return false;

    // Interpret fontString in the same way as the 'font' attribute of CanvasRenderingContext2D.
    RefPtrWillBeRawPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::create(HTMLStandardMode);
    CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, true, 0);
    if (parsedStyle->isEmpty())
        return false;

    String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont);
    if (fontValue == "inherit" || fontValue == "initial")
        return false;

    RefPtr<ComputedStyle> style = ComputedStyle::create();

    FontFamily fontFamily;
    fontFamily.setFamily(defaultFontFamily);

    FontDescription defaultFontDescription;
    defaultFontDescription.setFamily(fontFamily);
    defaultFontDescription.setSpecifiedSize(defaultFontSize);
    defaultFontDescription.setComputedSize(defaultFontSize);

    style->setFontDescription(defaultFontDescription);

    style->font().update(style->font().fontSelector());

    document()->ensureStyleResolver().computeFont(style.get(), *parsedStyle);

    font = style->font();
    font.update(document()->styleEngine().fontSelector());
    return true;
}
Beispiel #2
0
void RenderThemeQStyle::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element*) const
{
    // Ditch the border.
    style->resetBorder();

#ifdef Q_WS_MAC
    if (style->appearance() == PushButtonPart) {
        // The Mac ports ignore the specified height for <input type="button"> elements
        // unless a border and/or background CSS property is also specified.
        style->setHeight(Length(Auto));
    }
#endif

    FontDescription fontDescription = style->fontDescription();
    fontDescription.setIsAbsoluteSize(true);

#ifdef Q_WS_MAC // Use fixed font size and family on Mac (like Safari does)
    fontDescription.setSpecifiedSize(m_buttonFontPixelSize);
    fontDescription.setComputedSize(m_buttonFontPixelSize);
#else
    fontDescription.setSpecifiedSize(style->fontSize());
    fontDescription.setComputedSize(style->fontSize());
#endif

    FontFamily fontFamily;
    fontFamily.setFamily(m_buttonFontFamily);
    fontDescription.setFamily(fontFamily);
    style->setFontDescription(fontDescription);
    style->font().update(selector->fontSelector());
    style->setLineHeight(RenderStyle::initialLineHeight());
    setButtonSize(style);
    setButtonPadding(style);
}
static Font makeFont(const WebFontDescription& description)
{
    AtomicString::init();

    String fontFamilyString(description.family, description.familyLength);

    FontDescription f;
    FontFamily family;
    family.setFamily(fontFamilyString);
    f.setFamily(family);
    f.setSpecifiedSize(description.size);
    f.setComputedSize(description.size);
    f.setItalic(description.italic);
    f.setWeight(description.bold ? FontWeightBold : FontWeightNormal);
    f.setIsAbsoluteSize(true);

    FontSmoothingType smoothingType;
    if (SUCCEEDED(WebPreferences::sharedStandardPreferences()->fontSmoothing(&smoothingType)))
        f.setRenderingMode(smoothingType == FontSmoothingTypeWindows ? AlternateRenderingMode : NormalRenderingMode);

    Font font(f, 0, 0);
    font.update(0);

    return font;
}
Beispiel #4
0
// --------------------------------------------------------------
GFontWin32GDIPlus::GFontWin32GDIPlus( Font* nativeFont, const char * faceName, 
									  int size, int properties) 
						: mNativeFont(nativeFont), mName(faceName),
						  mSize(size), mFontProp(properties)
{
	DWORD count = (DWORD)mbstowcs(NULL, faceName, strlen(faceName));
	WCHAR * wstr = (WCHAR*) malloc ((count + 1) * sizeof(WCHAR));
	mbstowcs(wstr, faceName, strlen(faceName));
	FontCollection fc;
	FontFamily ff (wstr, &fc);
	int style;
	switch (properties) {
		case kFontBold:
			style = FontStyleBold;
			break;
		case kFontItalic:
			style = FontStyleItalic;
			break;
		case kFontBold+kFontItalic:
			style = FontStyleBoldItalic;
			break;
		case kFontUnderline:
			style = FontStyleUnderline;
			break;
		default:
			style = FontStyleRegular;
	}
	mEmHeight = ff.GetEmHeight(style);
	float ratio = mEmHeight ? (float)mEmHeight / size : 1.f;
	mAscent = ff.GetCellAscent(style) / ratio;
	mDescent = ff.GetCellDescent(style) / ratio;
	free (wstr);
}
Beispiel #5
0
static void 
gtk_cairo_draw_text(GraphicsContext *gc, const String& text, unsigned int length, int fontSize, int line) 
{
    // Need to create an empty document so that a CSSSelector can be created
    PassRefPtr<Document> document(Document::create(0));

    // Create the Font selector using this document
    PassRefPtr<CSSFontSelector> fontSelector = CSSFontSelector::create(document.get());

    // Use Arial as font family
    FontFamily family;
    family.setFamily("arial");

    // Create a font description to then assign to the font object
    FontDescription fontDescription = FontDescription();
    fontDescription.setFamily(family);
    fontDescription.setComputedSize(fontSize);
    fontDescription.setSpecifiedSize(fontSize);
    fontDescription.setWeight(FontWeightNormal);
    fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
    fontDescription.setKeywordSize(4);

    // Create the font and initialize it 
    static Font font(fontDescription, 0, 0);
    font.update(fontSelector);

    const UChar* string = text.characters();

    // When rtl has to be added, configure in TextRun constructor
    // TextRun textRun(string, length, 0, 0, 0, rtl, override, false, false);
    TextRun textRun(string, length);
    font.drawText(gc, textRun, FloatPoint(0, line*fontSize), 0, -1);

//    c->drawBidiText(font, textRun, location);
}
boolean gdiplus_textlayout(textpara_t *para, char **fontpath)
{
	/* ensure GDI+ is started up: since we get called outside of a job, we can't rely on GDI+ startup then */
	UseGdiplus();
	
	Layout* layout = new Layout(para->fontname, para->fontsize, para->str);
	
	/* measure the text */
	/* NOTE: use TextRenderingHintAntiAlias + GetGenericTypographic to get a layout without extra space at beginning and end */
	RectF boundingBox;
	DeviceContext deviceContext;
	Graphics measureGraphics(deviceContext.hdc);
	measureGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
	measureGraphics.MeasureString(
		&layout->text[0],
		layout->text.size(),
		layout->font,
		PointF(0.0f, 0.0f),
		GetGenericTypographic(),
		&boundingBox);
		
	FontFamily fontFamily;
	layout->font->GetFamily(&fontFamily);
	int style = layout->font->GetStyle();
		
	para->layout = (void*)layout;
	para->free_layout = &gdiplus_free_layout;
	para->width = boundingBox.Width;
	para->height = layout->font->GetHeight(&measureGraphics);
	para->yoffset_layout = fontFamily.GetCellAscent(style) * para->fontsize / fontFamily.GetEmHeight(style); /* convert design units to pixels */
	para->yoffset_centerline = 0;
	return TRUE;
};
Beispiel #7
0
void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
    // Ditch the border.
    style->resetBorder();

    // Height is locked to auto.
    style->setHeight(Length(Auto));

    // White-space is locked to pre
    style->setWhiteSpace(PRE);

    FontDescription fontDescription = style->fontDescription();
    fontDescription.setIsAbsoluteSize(true);

#ifdef Q_WS_MAC // Use fixed font size and family on Mac (like Safari does)
    fontDescription.setSpecifiedSize(m_buttonFontPixelSize);
    fontDescription.setComputedSize(m_buttonFontPixelSize);
#else
    fontDescription.setSpecifiedSize(style->fontSize());
    fontDescription.setComputedSize(style->fontSize());
#endif

    FontFamily fontFamily;
    fontFamily.setFamily(m_buttonFontFamily);
    fontDescription.setFamily(fontFamily);
    style->setFontDescription(fontDescription);
    style->setLineHeight(RenderStyle::initialLineHeight());

    setButtonSize(style);
    setButtonPadding(style);

    style->setColor(QApplication::palette().text().color());
}
Beispiel #8
0
void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
    // Ditch the border.
    style->resetBorder();

    // Height is locked to auto.
    style->setHeight(Length(Auto));

    // White-space is locked to pre
    style->setWhiteSpace(PRE);

    // Use fixed font size and family
    FontDescription fontDescription = style->fontDescription();
    fontDescription.setIsAbsoluteSize(true);
    fontDescription.setSpecifiedSize(m_buttonFontPixelSize);
    fontDescription.setComputedSize(m_buttonFontPixelSize);
    FontFamily fontFamily;
    fontFamily.setFamily(m_buttonFontFamily);
    fontDescription.setFamily(fontFamily);
    style->setFontDescription(fontDescription);
    style->setLineHeight(RenderStyle::initialLineHeight());

    setButtonSize(style);
    setButtonPadding(style);
}
// This installs a default typeface (from a hardcoded path) that allows
// layouts to work (not crash on null pointer) before the default
// typeface is set.
// TODO: investigate why layouts are being created before Typeface.java
// class initialization.
static FontCollection *makeFontCollection() {
    std::vector<FontFamily *>typefaces;
    const char *fns[] = {
        "/system/fonts/Roboto-Regular.ttf",
    };

    FontFamily *family = new FontFamily();
    for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) {
        const char *fn = fns[i];
        ALOGD("makeFontCollection adding %s", fn);
        SkTypeface *skFace = SkTypeface::CreateFromFile(fn);
        if (skFace != NULL) {
            // TODO: might be a nice optimization to get access to the underlying font
            // data, but would require us opening the file ourselves and passing that
            // to the appropriate Create method of SkTypeface.
            MinikinFont *font = new MinikinFontSkia(skFace, NULL, 0, 0);
            family->addFont(font);
            font->Unref();
        } else {
            ALOGE("failed to create font %s", fn);
        }
    }
    typefaces.push_back(family);

    FontCollection *result = new FontCollection(typefaces);
    family->Unref();
    return result;
}
Beispiel #10
0
/*!
	\brief This saves all family names and styles to the file specified in
	ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage.

	This operation is not done very often because the access to disk adds a significant 
	performance hit.

	The format for storage consists of two things: an array of strings with the name 'family'
	and a number of small string arrays which have the name of the font family. These are
	the style lists. 

	Additionally, any fonts which have bitmap strikes contained in them or any fonts which
	are fixed-width are named in the arrays 'tuned' and 'fixed'.
*/
void FontServer::SaveList(void)
{
	int32 famcount=0, stycount=0,i=0,j=0;
	FontFamily *fam;
	FontStyle *sty;
	BMessage fontmsg, familymsg('FONT');
	BString famname, styname, extraname;
	bool fixed,tuned;

	famcount=families->CountItems();
	for(i=0; i<famcount; i++)
	{
		fam=(FontFamily*)families->ItemAt(i);
		fixed=false;
		tuned=false;
		if(!fam)
			continue;

		famname=fam->Name();
				
		// Add the family to the message
		familymsg.AddString("name",famname);
		
		stycount=fam->CountStyles();
		for(j=0;j<stycount;j++)
		{
			styname.SetTo(fam->GetStyle(j));
			if(styname.CountChars()>0)
			{
				// Add to list
				familymsg.AddString("styles", styname);
				
				// Check to see if it has prerendered strikes (has "tuned" fonts)
				sty=fam->GetStyle(styname.String());
				if(!sty)
					continue;
				
				if(sty->HasTuned() && sty->IsScalable())
					tuned=true;

				// Check to see if it is fixed-width
				if(sty->IsFixedWidth())
					fixed=true;
			}
		}
		if(tuned)
			familymsg.AddBool("tuned",true);
		if(fixed)
			familymsg.AddBool("fixed",true);
		
		fontmsg.AddMessage("family",&familymsg);
		familymsg.MakeEmpty();
	}

	BFile file(SERVER_FONT_LIST,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
	if(file.InitCheck()==B_OK)
		fontmsg.Flatten(&file);
}
void CSSFontFace::load()
{
    FontDescription fontDescription;
    FontFamily fontFamily;
    fontFamily.setFamily(m_fontFace->family());
    fontDescription.setFamily(fontFamily);
    fontDescription.setTraits(m_fontFace->traits());
    load(fontDescription);
}
Beispiel #12
0
FontStyle*
FontManager::GetStyleByIndex(uint16 familyID, int32 index)
{
	FontFamily* family = GetFamily(familyID);
	if (family != NULL)
		return family->StyleAt(index);

	return NULL;
}
Beispiel #13
0
FontStyle*
FontManager::GetStyleByIndex(const char* familyName, int32 index)
{
	FontFamily* family = GetFamily(familyName);
	if (family != NULL)
		return family->StyleAt(index);

	return NULL;
}
Beispiel #14
0
/*!	\brief Counts the number of styles available in a font family
	\param family Name of the font family to scan
	\return The number of font styles currently available for the font family
*/
int32
FontManager::CountStyles(const char *familyName)
{
	_ScanFontsIfNecessary();

	FontFamily *family = GetFamily(familyName);
	if (family)
		return family->CountStyles();

	return 0;
}
Beispiel #15
0
/*!	\brief Adds the FontFamily/FontStyle that is represented by this path.
*/
status_t
FontManager::_AddFont(font_directory& directory, BEntry& entry)
{
	node_ref nodeRef;
	status_t status = entry.GetNodeRef(&nodeRef);
	if (status < B_OK)
		return status;

	BPath path;
	status = entry.GetPath(&path);
	if (status < B_OK)
		return status;

	FT_Face face;
	FT_Error error = FT_New_Face(gFreeTypeLibrary, path.Path(), 0, &face);
	if (error != 0)
		return B_ERROR;

	FontFamily *family = _FindFamily(face->family_name);
	if (family != NULL && family->HasStyle(face->style_name)) {
		// prevent adding the same style twice
		// (this indicates a problem with the installed fonts maybe?)
		FT_Done_Face(face);
		return B_OK;
	}

	if (family == NULL) {
		family = new (std::nothrow) FontFamily(face->family_name, fNextID++);
		if (family == NULL
			|| !fFamilies.BinaryInsert(family, compare_font_families)) {
			delete family;
			FT_Done_Face(face);
			return B_NO_MEMORY;
		}
	}

	FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));

	// the FontStyle takes over ownership of the FT_Face object
	FontStyle *style = new FontStyle(nodeRef, path.Path(), face);
	if (!family->AddStyle(style)) {
		delete style;
		delete family;
		return B_NO_MEMORY;
	}

	directory.styles.AddItem(style);
	fStyleHashTable.AddItem(style);

	if (directory.AlreadyScanned())
		directory.revision++;

	return B_OK;
}
Beispiel #16
0
/*!	\brief Counts the number of styles available in a font family
	\param family Name of the font family to scan
	\return The number of font styles currently available for the font family
*/
int32
FontManager::CountStyles(uint16 familyID)
{
	_ScanFontsIfNecessary();

	FontFamily *family = GetFamily(familyID);
	if (family)
		return family->CountStyles();

	return 0;
}
Beispiel #17
0
static Font dragLabelFont(int size, bool bold)
{
    FontDescription desc;
    desc.setWeight(bold ? FontWeightBold : FontWeightNormal);
    FontFamily family;
    family.setFamily("Lucida Grande");
    desc.setFamily(family);
    desc.setSpecifiedSize((float)size);
    desc.setComputedSize((float)size);
    Font result = Font(desc, 0, 0); 
    result.update(0);
    return result;
}
Beispiel #18
0
CanvasFontCache::CanvasFontCache(Document& document)
    : m_document(&document), m_pruningScheduled(false) {
  FontFamily fontFamily;
  fontFamily.setFamily(defaultFontFamily);
  FontDescription defaultFontDescription;
  defaultFontDescription.setFamily(fontFamily);
  defaultFontDescription.setSpecifiedSize(defaultFontSize);
  defaultFontDescription.setComputedSize(defaultFontSize);
  m_defaultFontStyle = ComputedStyle::create();
  m_defaultFontStyle->setFontDescription(defaultFontDescription);
  m_defaultFontStyle->font().update(
      m_defaultFontStyle->font().getFontSelector());
}
Beispiel #19
0
/*!	\brief If you don't find your preferred font style, but are anxious
		to have one fitting your needs, you may want to use this method.
*/
FontStyle*
FontManager::FindStyleMatchingFace(uint16 face) const
{
	int32 count = fFamilies.CountItems();

	for (int32 i = 0; i < count; i++) {
		FontFamily* family = fFamilies.ItemAt(i);
		FontStyle* style = family->GetStyleMatchingFace(face);
		if (style != NULL)
			return style;
	}

	return NULL;
}
Beispiel #20
0
bool operator==(const FontFamily& a, const FontFamily& b)
{
    if (a.family() != b.family())
        return false;
    const FontFamily* ap;
    const FontFamily* bp;
    for (ap = a.next(), bp = b.next(); ap != bp; ap = ap->next(), bp = bp->next()) {
        if (!ap || !bp)
            return false;
        if (ap->family() != bp->family())
            return false;
    }
    return true;
}
Beispiel #21
0
/*!
	\brief Protected function which locates a FontFamily object
	\param name The family to find
	\return Pointer to the specified family or NULL if not found.
	
	Do NOT delete the FontFamily returned by this function.
*/
FontFamily *FontServer::_FindFamily(const char *name)
{
	if(!init)
		return NULL;
	int32 count=families->CountItems(), i;
	FontFamily *family;
	for(i=0; i<count; i++)
	{
		family=(FontFamily*)families->ItemAt(i);
		if(strcmp(family->Name(),name)==0)
			return family;
	}
	return NULL;
}
Font createTestFont(const AtomicString& familyName, const String& fontPath, float size)
{
    FontFamily family;
    family.setFamily(familyName);

    FontDescription fontDescription;
    fontDescription.setFamily(family);
    fontDescription.setSpecifiedSize(size);
    fontDescription.setComputedSize(size);

    Font font(fontDescription);
    font.update(TestFontSelector::create(fontPath));
    return font;
}
Beispiel #23
0
/*!	\brief This call is used by the FontStyle class - and the FontStyle class
		only - to remove itself from the font manager.
	At this point, the style is already no longer available to the user.
*/
void
FontManager::RemoveStyle(FontStyle* style)
{
	FontFamily* family = style->Family();
	if (family == NULL)
		debugger("family is NULL!");

	FontStyle* check = GetStyle(family->ID(), style->ID());
	if (check != NULL)
		debugger("style removed but still available!");

	if (family->RemoveStyle(style)
		&& family->CountStyles() == 0)
		fFamilies.RemoveItem(family);
}
Beispiel #24
0
SFont *FontServer::OpenFont( const std::string & cFamily, const std::string & cStyle )
{
	FontFamily *pcFamily;
	SFont *pcFont = NULL;

	if( Lock() )
	{
		if( ( pcFamily = FindFamily( cFamily ) ) )
		{
			pcFont = pcFamily->FindStyle( cStyle );
		}
		Unlock();
	}
	return ( pcFont );
}
Beispiel #25
0
void FontFace::load(ExecutionContext* context)
{
    if (m_status != Unloaded)
        return;

    FontDescription fontDescription;
    FontFamily fontFamily;
    fontFamily.setFamily(m_family);
    fontDescription.setFamily(fontFamily);
    fontDescription.setTraits(traits());

    CSSFontSelector* fontSelector = toDocument(context)->styleEngine()->fontSelector();
    m_cssFontFace->load(fontDescription, fontSelector);
    fontSelector->loadPendingFonts();
}
Beispiel #26
0
	Font::Font(FontFamily &font_family, float height)
	{
		font_family.throw_if_null();
		FontDescription desc;
		desc.set_height(height);
		*this = Font(font_family, desc);
	}
Beispiel #27
0
bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font)
{
    if (fontString.isEmpty())
        return false;

    // Interpret fontString in the same way as the 'font' attribute of CanvasRenderingContext2D.
    RefPtr<MutableStylePropertySet> parsedStyle = MutableStylePropertySet::create();
    BisonCSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, fontString, HTMLStandardMode, 0);
    if (parsedStyle->isEmpty())
        return false;

    String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont);
    if (fontValue == "inherit" || fontValue == "initial")
        return false;

    RefPtr<RenderStyle> style = RenderStyle::create();

    FontFamily fontFamily;
    fontFamily.setFamily(defaultFontFamily);

    FontDescription defaultFontDescription;
    defaultFontDescription.setFamily(fontFamily);
    defaultFontDescription.setSpecifiedSize(defaultFontSize);
    defaultFontDescription.setComputedSize(defaultFontSize);

    style->setFontDescription(defaultFontDescription);

    style->font().update(style->font().fontSelector());

    // Now map the font property longhands into the style.
    CSSPropertyValue properties[] = {
        CSSPropertyValue(CSSPropertyFontFamily, *parsedStyle),
        CSSPropertyValue(CSSPropertyFontStretch, *parsedStyle),
        CSSPropertyValue(CSSPropertyFontStyle, *parsedStyle),
        CSSPropertyValue(CSSPropertyFontVariant, *parsedStyle),
        CSSPropertyValue(CSSPropertyFontWeight, *parsedStyle),
        CSSPropertyValue(CSSPropertyFontSize, *parsedStyle),
        CSSPropertyValue(CSSPropertyLineHeight, *parsedStyle),
    };
    StyleResolver& styleResolver = document()->styleResolver();
    styleResolver.applyPropertiesToStyle(properties, WTF_ARRAY_LENGTH(properties), style.get());

    font = style->font();
    font.update(document()->styleEngine()->fontSelector());
    return true;
}
static Font dragLabelFont(int size, bool bold, FontRenderingMode renderingMode)
{
    NONCLIENTMETRICS metrics;
    metrics.cbSize = sizeof(metrics);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
    FontDescription desc;
    desc.setWeight(bold ? FontWeightBold : FontWeightNormal);
    FontFamily family;
    family.setFamily(metrics.lfSmCaptionFont.lfFaceName);
    desc.setFamily(family);
    desc.setSpecifiedSize((float)size);
    desc.setComputedSize((float)size);
    desc.setRenderingMode(renderingMode);
    Font result = Font(desc, 0, 0); 
    result.update(0);
    return result;
}
WebFontDescription::operator FontDescription() const
{
    FontFamily fontFamily;
    fontFamily.setFamily(family);

    FontDescription desc;
    desc.setFamily(fontFamily);
    desc.setGenericFamily(static_cast<FontDescription::GenericFamilyType>(genericFamily));
    desc.setSpecifiedSize(size);
    desc.setComputedSize(size);
    desc.setStyle(italic ? FontStyleItalic : FontStyleNormal);
    desc.setVariant(smallCaps ? FontVariantSmallCaps : FontVariantNormal);
    desc.setWeight(static_cast<FontWeight>(weight));
    desc.setFontSmoothing(static_cast<FontSmoothingMode>(smoothing));
    desc.setLetterSpacing(letterSpacing);
    desc.setWordSpacing(wordSpacing);
    return desc;
}
Beispiel #30
0
	Font_Impl::Font_Impl(FontFamily &new_font_family, const FontDescription &description)
	{
		new_font_family.throw_if_null();

		font_family = new_font_family;

		selected_description = description.clone();
		selected_line_height = description.get_line_height();
	}