void SVGGradient::parse(xmlNodePtr node) { attribs.parseNode(node); const char *tmp = attribs["gradientUnits"]; if(tmp) { if(!strcmp(tmp, "userSpaceOnUse")) { userSpace = true; } else { userSpace = false; } } else { userSpace = false; } parseGradient(); parseSpreadMethod(); parseTransform(); parseStops(node); }
SvgGradientHelper* SvgParser::findGradient(const QString &id, const QString &href) { // check if gradient was already parsed, and return it if (m_gradients.contains(id)) return &m_gradients[ id ]; // check if gradient was stored for later parsing if (!m_context.hasDefinition(id)) return 0; const KoXmlElement &e = m_context.definition(id); if (!e.tagName().contains("Gradient")) return 0; if (e.childNodesCount() == 0) { QString mhref = e.attribute("xlink:href").mid(1); if (m_context.hasDefinition(mhref)) return findGradient(mhref, id); else return 0; } else { // ok parse gradient now if (! parseGradient(m_context.definition(id), m_context.definition(href))) return 0; } // return successfully parsed gradient or NULL QString n; if (href.isEmpty()) n = id; else n = href; if (m_gradients.contains(n)) return &m_gradients[ n ]; else return 0; }
MythFontProperties *MythFontProperties::ParseFromXml( const QString &filename, const QDomElement &element, MythUIType *parent, bool addToGlobal, bool showWarnings) { // Crappy, but cached. Move to GlobalFontMap? static bool show_available = true; bool fromBase = false; MythFontProperties *newFont = new MythFontProperties(); newFont->Freeze(); if (element.tagName() == "font") LOG(VB_GENERAL, LOG_WARNING, LOC + QString("File %1: Use of 'font' is deprecated in favour of " "'fontdef'") .arg(filename)); QString name = element.attribute("name", ""); if (name.isEmpty()) { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element, "Font requires a name"); delete newFont; return NULL; } QString base = element.attribute("from", ""); if (!base.isEmpty()) { MythFontProperties *tmp = NULL; if (parent) tmp = parent->GetFont(base); if (!tmp) tmp = GetGlobalFontMap()->GetFont(base); if (!tmp) { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element, QString("Specified base font '%1' does not exist.").arg(base)); delete newFont; return NULL; } *newFont = *tmp; fromBase = true; } int size, pixelsize; size = pixelsize = -1; QString face = element.attribute("face", ""); if (face.isEmpty()) { if (!fromBase) { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element, "Font needs a face"); delete newFont; return NULL; } } else { newFont->m_face.setFamily(face); } if (addToGlobal && GetGlobalFontMap()->Contains(name)) { MythFontProperties *tmp = GetGlobalFontMap()->GetFont(name); if (showWarnings) { VERBOSE_XML(VB_GENERAL, LOG_WARNING, filename, element, QString("Attempting to define '%1'\n\t\t\t" "with face '%2', but it already " "exists with face '%3'") .arg(name).arg(QFontInfo(newFont->m_face).family()) .arg((tmp) ? QFontInfo(tmp->m_face).family() : "ERROR")); } delete newFont; return NULL; } QString hint = element.attribute("stylehint", ""); if (!hint.isEmpty()) { newFont->m_face.setStyleHint((QFont::StyleHint)hint.toInt()); } for (QDomNode child = element.firstChild(); !child.isNull(); child = child.nextSibling()) { QDomElement info = child.toElement(); if (!info.isNull()) { if (info.tagName() == "size") { size = getFirstText(info).toInt(); } else if (info.tagName() == "pixelsize") { pixelsize = getFirstText(info).toInt(); } else if (info.tagName() == "color") { newFont->m_brush = QBrush(QColor(getFirstText(info))); } else if (info.tagName() == "gradient") { newFont->m_brush = parseGradient(info); } else if (info.tagName() == "shadowcolor") { newFont->m_shadowColor = QColor(getFirstText(info)); } else if (info.tagName() == "shadowoffset") { newFont->m_hasShadow = true; newFont->m_shadowOffset = parsePoint(info, false); } else if (info.tagName() == "shadowalpha") { newFont->m_shadowAlpha = getFirstText(info).toInt(); } else if (info.tagName() == "outlinecolor") { newFont->m_outlineColor = QColor(getFirstText(info)); } else if (info.tagName() == "outlinesize") { newFont->m_hasOutline = true; newFont->m_outlineSize = getFirstText(info).toInt(); } else if (info.tagName() == "outlinealpha") { newFont->m_outlineAlpha = getFirstText(info).toInt(); } else if (info.tagName() == "italics") { newFont->m_face.setItalic(parseBool(info)); } else if (info.tagName() == "letterspacing") { newFont->m_face.setLetterSpacing(QFont::AbsoluteSpacing, getFirstText(info).toInt()); } else if (info.tagName() == "wordspacing") { newFont->m_face.setWordSpacing(getFirstText(info).toInt()); } else if (info.tagName() == "decoration") { QString dec = getFirstText(info).toLower(); QStringList values = dec.split(','); QStringList::Iterator it; for ( it = values.begin(); it != values.end(); ++it ) { if (*it == "underline") newFont->m_face.setUnderline(true); else if (*it == "overline") newFont->m_face.setOverline(true); else if (*it == "strikeout") newFont->m_face.setStrikeOut(true); } } else if (info.tagName() == "weight") { QString weight = getFirstText(info).toLower(); if (weight == "ultralight" || weight == "1") newFont->m_face.setWeight(1); else if (weight == "light" || weight == "2") newFont->m_face.setWeight(QFont::Light); else if (weight == "normal" || weight == "3") newFont->m_face.setWeight(QFont::Normal); else if (weight == "demibold" || weight == "4") newFont->m_face.setWeight(QFont::DemiBold); else if (weight == "bold" || weight == "5") newFont->m_face.setWeight(QFont::Bold); else if (weight == "black" || weight == "6") newFont->m_face.setWeight(QFont::Black); else if (weight == "ultrablack" || weight == "7") newFont->m_face.setWeight(99); else newFont->m_face.setWeight(QFont::Normal); } else if (info.tagName() == "stretch") { QString stretch = getFirstText(info).toLower(); if (stretch == "ultracondensed" || stretch == "1") newFont->m_stretch = QFont::UltraCondensed; else if (stretch == "extracondensed" || stretch == "2") newFont->m_stretch = QFont::ExtraCondensed; else if (stretch == "condensed" || stretch == "3") newFont->m_stretch = QFont::Condensed; else if (stretch == "semicondensed" || stretch == "4") newFont->m_stretch = QFont::SemiCondensed; else if (stretch == "unstretched" || stretch == "5") newFont->m_stretch = QFont::Unstretched; else if (stretch == "semiexpanded" || stretch == "6") newFont->m_stretch = QFont::SemiExpanded; else if (stretch == "expanded" || stretch == "7") newFont->m_stretch = QFont::Expanded; else if (stretch == "extraexpanded" || stretch == "8") newFont->m_stretch = QFont::ExtraExpanded; else if (stretch == "ultraexpanded" || stretch == "9") newFont->m_stretch = QFont::UltraExpanded; else newFont->m_stretch = QFont::Unstretched; newFont->m_face.setStretch(newFont->m_stretch); } else { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, info, QString("Unknown tag in font '%1'").arg(name)); delete newFont; return NULL; } } } if (size <= 0 && pixelsize <= 0 && !fromBase) { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element, "Font size must be greater than 0."); delete newFont; return NULL; } else if (pixelsize > 0) { newFont->SetPixelSize(pixelsize); } else if (size > 0) { newFont->SetPointSize(size); } newFont->Unfreeze(); QFontInfo fi(newFont->m_face); if (newFont->m_face.family() != fi.family()) { VERBOSE_XML(VB_GENERAL, LOG_ERR, filename, element, QString("Failed to load '%1', got '%2' instead") .arg(newFont->m_face.family()).arg(fi.family())); if (show_available) { LOG(VB_GUI, LOG_DEBUG, "Available fonts:"); QFontDatabase database; foreach (const QString &family, database.families()) { QStringList family_styles; family_styles << family + "::"; foreach (const QString &style, database.styles(family)) { family_styles << style + ":"; QString sizes; bool tic = false; foreach (int points, database.smoothSizes(family, style)) { if (tic) sizes += ","; tic = true; sizes += QString::number(points); } sizes += "; "; family_styles << sizes.trimmed(); } LOG(VB_GUI, LOG_DEBUG, family_styles.join(" ")); } show_available = false; } }