bool SkFontDownloadList::isExist( const char * fontAppName ) { if( numFonts() == 0 ) return false; else { SkFontData ** fonts = getFonts(); for( uint32_t n = 0 ; n < numFonts() ; n++ ) if( !strcmp( fontAppName, fonts[n]->getFontAppName() ) ) return true; return false; } }
bool Layout::loadFromFile() { QFile file("my layouts/" + filename + ".xml"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::warning(NULL, tr("Error"), tr("Could not load layout: %1 because the file could not be opened!").arg(filename)); return false; } QXmlStreamReader stream(&file); while (!stream.atEnd()) { stream.readNext(); if (stream.tokenType() != QXmlStreamReader::StartElement) continue; if (stream.name() == "Layout") { float width = stream.attributes().value("aspectWidth").toString().toInt(); float height = stream.attributes().value("aspectHeight").toString().toInt(); aspect = width / height; } else if (stream.name() == "Background") { QStringRef ref = stream.attributes().value("color"); if (!ref.isEmpty()) { has_background_color = true; background_color = QColor(ref.toString()); } ref = stream.attributes().value("image"); if (!ref.isEmpty()) { background_image = new QPixmap("my layouts/" + ref.toString()); owns_background_image = true; } } else if (stream.name() == "Font") { Font* new_font = new Font; new_font->family = stream.attributes().value("family").toString(); new_font->size = stream.attributes().value("size").toString().toFloat(); QStringRef ref = stream.attributes().value("lineSpacing"); if (ref.isEmpty()) new_font->line_spacing = 1; else new_font->line_spacing = ref.toString().toFloat(); ref = stream.attributes().value("weight"); if (ref.isEmpty()) new_font->weight = QFont::Normal; else { if (ref == "normal") new_font->weight = QFont::Normal; else if (ref == "bold") new_font->weight = QFont::Bold; else if (ref == "black") new_font->weight = QFont::Black; else { // TODO: Error message delete new_font; return false; } } new_font->color = QColor(stream.attributes().value("color").toString()); fonts.insert(std::make_pair(stream.attributes().value("id").toString(), new_font)); } else if (stream.name() == "Rect") { Rect* new_rect = new Rect(); new_rect->rect = QRectF(QPointF(stream.attributes().value("left").toString().toFloat(), stream.attributes().value("top").toString().toFloat()), QPointF(stream.attributes().value("right").toString().toFloat(), stream.attributes().value("bottom").toString().toFloat())); getFonts(stream.attributes(), new_rect->font_normal, new_rect->font_strong); rects.insert(std::make_pair(stream.attributes().value("id").toString(), new_rect)); } else if (stream.name() == "Point") { Point* new_point = new Point(); new_point->pos = QPointF(stream.attributes().value("x").toString().toFloat(), stream.attributes().value("y").toString().toFloat()); getFonts(stream.attributes(), new_point->font_normal, new_point->font_strong); QStringRef ref = stream.attributes().value("max_width"); if (ref.isEmpty()) new_point->max_width = -1; else new_point->max_width = ref.toString().toFloat(); Qt::Alignment align_h = Qt::AlignHCenter; QString temp = stream.attributes().value("align_h").toString(); if (temp == "left") align_h = Qt::AlignLeft; else if (temp == "right") align_h = Qt::AlignRight; Qt::Alignment align_v = Qt::AlignVCenter; temp = stream.attributes().value("align_v").toString(); if (temp == "bottom") align_v = Qt::AlignBottom; else if (temp == "top") align_v = Qt::AlignTop; else if (temp == "baseline") align_v = Qt::AlignAbsolute; // NOTE: This is being misused as there seems to be no "baseline" flag! new_point->strong_font = false; new_point->alignment = align_h | align_v; ref = stream.attributes().value("text"); if (ref.isEmpty()) new_point->text = ""; else new_point->text = ref.toString(); points.insert(std::make_pair(stream.attributes().value("id").toString(), new_point)); } } return true; }