本文整理汇总了C++中FontDescription类的典型用法代码示例。如果您正苦于以下问题:C++ FontDescription类的具体用法?C++ FontDescription怎么用?C++ FontDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FontDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFont
RefPtr<Font> CachedSVGFont::createFont(const FontDescription& fontDescription, const AtomicString& remoteURI, bool syntheticBold, bool syntheticItalic, bool externalSVG)
{
#if ENABLE(SVG_OTF_CONVERTER)
if (!externalSVG || firstFontFace(remoteURI))
return CachedFont::createFont(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG);
#else
if (!externalSVG)
return CachedFont::createFont(fontDescription, remoteURI, syntheticBold, syntheticItalic, externalSVG);
if (SVGFontFaceElement* firstFontFace = this->firstFontFace(remoteURI))
return Font::create(std::make_unique<SVGFontData>(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
#endif
return nullptr;
}
示例2: adoptRef
FontPlatformData::FontPlatformData(FcPattern* pattern, const FontDescription& fontDescription)
: m_pattern(pattern)
, m_fallbacks(0)
, m_size(fontDescription.computedPixelSize())
, m_syntheticBold(false)
, m_syntheticOblique(false)
, m_fixedWidth(false)
, m_scaledFont(0)
{
RefPtr<cairo_font_face_t> fontFace = adoptRef(cairo_ft_font_face_create_for_pattern(m_pattern.get()));
initializeWithFontFace(fontFace.get());
int spacing;
if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) == FcResultMatch && spacing == FC_MONO)
m_fixedWidth = true;
if (fontDescription.weight() >= FontWeightBold) {
// The FC_EMBOLDEN property instructs us to fake the boldness of the font.
FcBool fontConfigEmbolden;
if (FcPatternGetBool(pattern, FC_EMBOLDEN, 0, &fontConfigEmbolden) == FcResultMatch)
m_syntheticBold = fontConfigEmbolden;
}
}
示例3: ASSERT_NOT_REACHED
HRESULT STDMETHODCALLTYPE DOMElement::font(WebFontDescription* webFontDescription)
{
if (!webFontDescription) {
ASSERT_NOT_REACHED();
return E_POINTER;
}
ASSERT(m_element);
WebCore::RenderObject* renderer = m_element->renderer();
if (!renderer)
return E_FAIL;
FontDescription fontDescription = renderer->style()->font().fontDescription();
AtomicString family = fontDescription.firstFamily();
webFontDescription->family = family.characters();
webFontDescription->familyLength = family.length();
webFontDescription->size = fontDescription.computedSize();
webFontDescription->bold = fontDescription.weight() >= WebCore::FontWeight600;
webFontDescription->italic = fontDescription.italic();
return S_OK;
}
示例4: substituteDescription
PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle(
const FontDescription& fontDescription,
UChar32 character) {
FontDescription substituteDescription(fontDescription);
substituteDescription.setStyle(FontStyleNormal);
substituteDescription.setWeight(FontWeightNormal);
FontFaceCreationParams creationParams(
substituteDescription.family().family());
FontPlatformData* substitutePlatformData =
getFontPlatformData(substituteDescription, creationParams);
if (substitutePlatformData &&
substitutePlatformData->fontContainsCharacter(character)) {
FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600);
platformData.setSyntheticItalic(
fontDescription.style() == FontStyleItalic ||
fontDescription.style() == FontStyleOblique);
return fontDataFromFontPlatformData(&platformData, DoNotRetain);
}
return nullptr;
}
示例5: fontDataForGenericFamily
PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName)
{
if (m_fontFaces.isEmpty()) {
if (familyName.startsWith("-webkit-"))
return fontDataForGenericFamily(m_document, fontDescription, familyName);
if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard");
return 0;
}
CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName);
// If no face was found, then return 0 and let the OS come up with its best match for the name.
if (!face) {
// If we were handed a generic family, but there was no match, go ahead and return the correct font based off our
// settings.
if (fontDescription.genericFamily() == FontDescription::StandardFamily && !fontDescription.isSpecifiedFont())
return fontDataForGenericFamily(m_document, fontDescription, "-webkit-standard");
return fontDataForGenericFamily(m_document, fontDescription, familyName);
}
// We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over.
return face->getFontData(fontDescription);
}
示例6: FontPlatformDataPrivate
FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing)
: m_data(adoptRef(new FontPlatformDataPrivate()))
{
QFont font;
int requestedSize = description.computedPixelSize();
font.setFamily(familyName);
if (requestedSize)
font.setPixelSize(requestedSize);
font.setItalic(description.italic());
font.setWeight(toQFontWeight(description.weight()));
font.setWordSpacing(wordSpacing);
font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
if (description.fontSmoothing() == NoSmoothing
|| (description.fontSmoothing() == AutoSmoothing && !Font::shouldUseSmoothing()))
font.setStyleStrategy(QFont::NoAntialias);
m_data->bold = font.bold();
// WebKit allows font size zero but QFont does not. We will return
// m_data->size if a font size of zero is requested and pixelSize()
// otherwise.
m_data->size = (!requestedSize) ? requestedSize : font.pixelSize();
m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
}
示例7: cloneRenderStyleWithState
void TextAutoSizingValue::reset()
{
HashSet<RefPtr<Node> >::iterator end = m_autoSizedNodes.end();
for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) {
const RefPtr<Node>& autoSizingNode = *i;
RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
if (!text)
continue;
// Reset the font size back to the original specified size
FontDescription fontDescription = text->style().fontDescription();
float originalSize = fontDescription.specifiedSize();
if (fontDescription.computedSize() != originalSize) {
fontDescription.setComputedSize(originalSize);
RefPtr<RenderStyle> style = cloneRenderStyleWithState(text->style());
style->setFontDescription(fontDescription);
style->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector());
text->parent()->setStyle(style.releaseNonNull());
}
// Reset the line height of the parent.
RenderElement* parentRenderer = text->parent();
if (!parentRenderer)
continue;
if (parentRenderer->isAnonymousBlock())
parentRenderer = parentRenderer->parent();
const RenderStyle& parentStyle = parentRenderer->style();
Length originalLineHeight = parentStyle.specifiedLineHeight();
if (originalLineHeight != parentStyle.lineHeight()) {
RefPtr<RenderStyle> newParentStyle = cloneRenderStyleWithState(parentStyle);
newParentStyle->setLineHeight(originalLineHeight);
newParentStyle->setFontDescription(fontDescription);
newParentStyle->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector());
parentRenderer->setStyle(newParentStyle.releaseNonNull());
}
}
}
示例8: fillFontDescription
static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFont, float fontSize)
{
fontDescription.setIsAbsoluteSize(true);
fontDescription.setGenericFamily(FontDescription::NoFamily);
fontDescription.firstFamily().setFamily(String(logFont.lfFaceName));
fontDescription.setSpecifiedSize(fontSize);
fontDescription.setWeight(logFont.lfWeight >= 700 ? FontWeightBold : FontWeightNormal); // FIXME: Use real weight.
fontDescription.setItalic(logFont.lfItalic);
}
示例9: FontPlatformDataPrivate
FontPlatformData::FontPlatformData(const FontDescription& description, const AtomicString& familyName, int wordSpacing, int letterSpacing)
: m_data(adoptRef(new FontPlatformDataPrivate()))
{
QFont& font = m_data->font;
int requestedSize = description.computedPixelSize();
font.setFamily(familyName);
font.setPixelSize(requestedSize);
font.setItalic(description.italic());
font.setWeight(toQFontWeight(description.weight()));
font.setWordSpacing(wordSpacing);
font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);
const bool smallCaps = description.smallCaps();
font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);
font.setStyleStrategy(QFont::ForceIntegerMetrics);
m_data->bold = font.bold();
// WebKit allows font size zero but QFont does not. We will return
// m_data->size if a font size of zero is requested and pixelSize()
// otherwise.
m_data->size = (!requestedSize) ? requestedSize : font.pixelSize();
#if HAVE(QRAWFONT)
m_data->rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
#endif
}
示例10: resolveFontStyle
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.
MutableStylePropertySet* parsedStyle =
MutableStylePropertySet::create(HTMLStandardMode);
CSSParser::parseValue(parsedStyle, 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().getFontSelector());
document()->ensureStyleResolver().computeFont(style.get(), *parsedStyle);
font = style->font();
font.update(document()->styleEngine().fontSelector());
return true;
}
示例11: m
//------------------------------------------------------------------------------
bool
Font::Load(const FontDescription& d)
{
if (d.IsBold() == true)
this->font.setWeight(QFont::Bold);
else
this->font.setWeight(QFont::Normal);
if (d.IsItalic() == true)
this->font.setStyle(QFont::StyleItalic);
else
this->font.setStyle(QFont::StyleNormal);
if (d.IsMonospace() == true)
this->font.setFamily("Courier");
else
this->font.setFamily("Sans");
this->font.setPointSize(d.GetHeight());
QFontMetrics m(this->font);
this->height = m.height();
this->ascent_height = m.ascent();
this->capital_height = this->height;
this->initialized = true;
return true;
}
示例12: initializeWithFontFace
void FontPlatformData::initializeWithFontFace(cairo_font_face_t* fontFace, const FontDescription& fontDescription)
{
cairo_font_options_t* options = getDefaultFontOptions();
cairo_matrix_t ctm;
cairo_matrix_init_identity(&ctm);
// Scaling a font with width zero size leads to a failed cairo_scaled_font_t instantiations.
// Instead we scale we scale the font to a very tiny size and just abort rendering later on.
float realSize = m_size ? m_size : 1;
cairo_matrix_t fontMatrix;
if (!m_pattern)
cairo_matrix_init_scale(&fontMatrix, realSize, realSize);
else {
setCairoFontOptionsFromFontConfigPattern(options, m_pattern.get());
// FontConfig may return a list of transformation matrices with the pattern, for instance,
// for fonts that are oblique. We use that to initialize the cairo font matrix.
FcMatrix fontConfigMatrix, *tempFontConfigMatrix;
FcMatrixInit(&fontConfigMatrix);
// These matrices may be stacked in the pattern, so it's our job to get them all and multiply them.
for (int i = 0; FcPatternGetMatrix(m_pattern.get(), FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++)
FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix);
cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx,
-fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0);
// We requested an italic font, but Fontconfig gave us one that was neither oblique nor italic.
int actualFontSlant;
if (fontDescription.italic() && FcPatternGetInteger(m_pattern.get(), FC_SLANT, 0, &actualFontSlant) == FcResultMatch)
m_syntheticOblique = actualFontSlant == FC_SLANT_ROMAN;
// The matrix from FontConfig does not include the scale.
cairo_matrix_scale(&fontMatrix, realSize, realSize);
}
if (syntheticOblique()) {
static const float syntheticObliqueSkew = -tanf(14 * acosf(0) / 90);
cairo_matrix_t skew = {1, 0, syntheticObliqueSkew, 1, 0, 0};
cairo_matrix_multiply(&fontMatrix, &skew, &fontMatrix);
}
m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options);
cairo_font_options_destroy(options);
}
示例13: TEST
TEST(FontDescriptionTest, TestHashCollision)
{
FontWeight weights[] = {
FontWeight100,
FontWeight200,
FontWeight300,
FontWeight400,
FontWeight500,
FontWeight600,
FontWeight700,
FontWeight800,
FontWeight900,
};
FontStretch stretches[] {
FontStretchUltraCondensed,
FontStretchExtraCondensed,
FontStretchCondensed,
FontStretchSemiCondensed,
FontStretchNormal,
FontStretchSemiExpanded,
FontStretchExpanded,
FontStretchExtraExpanded,
FontStretchUltraExpanded
};
FontStyle styles[] = {
FontStyleNormal,
FontStyleOblique,
FontStyleItalic
};
FontVariant variants[] = {
FontVariantNormal,
FontVariantSmallCaps
};
FontDescription source;
WTF::Vector<unsigned> hashes;
for (size_t i = 0; i < WTF_ARRAY_LENGTH(weights); i++) {
source.setWeight(weights[i]);
for (size_t j = 0; j < WTF_ARRAY_LENGTH(stretches); j++) {
source.setStretch(stretches[j]);
for (size_t k = 0; k < WTF_ARRAY_LENGTH(styles); k++) {
source.setStyle(styles[k]);
for (size_t m = 0; m < WTF_ARRAY_LENGTH(variants); m++) {
source.setVariant(variants[m]);
unsigned hash = source.styleHashWithoutFamilyList();
ASSERT_FALSE(hashes.contains(hash));
hashes.append(hash);
}
}
}
}
}
示例14: alt
RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& desc, const Font* originalFontData, bool isPlatformFont, const UChar* characters, unsigned int length)
{
ASSERT(characters && (length==1||length==2));
UChar32 c = 0;
if (length==1) {
c = characters[0];
} else {
c = U16_GET_SUPPLEMENTARY(characters[0], characters[1]);
}
FontPlatformData alt(desc, desc.familyAt(0));
if (alt.font() && alt.font()->font()) {
alt.font()->setSpecificUnicodeChar(c);
return fontForPlatformData(alt);
} else {
return lastResortFallbackFont(desc);
}
}
示例15: fontPlatformData
FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& fontDescription, bool bold, bool italic)
{
int size = fontDescription.computedPixelSize();
FontOrientation orientation = fontDescription.orientation();
FontWidthVariant widthVariant = fontDescription.widthVariant();
#if CORETEXT_WEB_FONTS
RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
if (font && fontDescription.featureSettings() && fontDescription.featureSettings()->size())
font = applyFontFeatureSettings(font.get(), *fontDescription.featureSettings());
return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant);
#else
return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant);
#endif
}