QImage SvgElementProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize) { // Resolve URL QUrl url = QUrl(id); if (url.isRelative() && !mBaseUrl.isEmpty()) url = mBaseUrl.resolved(url); if (!url.isValid()) return placeholder(QString("Invalid URL\nBase: %1\nInput: %2").arg(mBaseUrl.toString()).arg(id), requestedSize); // Make a filename from the given URL QString imagepath = QQmlFile::urlToLocalFileOrQrc(url); // Fragment is used to specify SVG element QString elementId = url.fragment(); // Load image QSvgRenderer renderer; if (!renderer.load(imagepath)) { qWarning() << "Unable to load image:" << imagepath; return placeholder(QStringLiteral("Unable to load image:\n") + imagepath, requestedSize); } // Check whether requested element exists if (!elementId.isEmpty() && !renderer.elementExists(elementId)) return placeholder(QStringLiteral("Unable to find element:\n") + elementId + "\nin image:\n" + imagepath, requestedSize); // Get image or element size QSize itemSize = elementId.isEmpty() ? renderer.defaultSize() : renderer.boundsOnElement(elementId).size().toSize(); if (size) *size = itemSize; // Create image QImage image(requestedSize.width() > 0 ? requestedSize.width() : itemSize.width(), requestedSize.height() > 0 ? requestedSize.height() : itemSize.height(), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); // Paint svg or element QPainter p(&image); if (elementId.isEmpty()) renderer.render(&p); else renderer.render(&p, elementId); return image; }
Rule::Rule(Entry& source, bool isVisible, EntryPathFollower& pathFollower, std::list<std::list<std::string> > const& pathesToIgnore, std::list<std::string> const& currentPath) : type(Rule::NORMAL), isVisible(isVisible), __idpath(currentPath), outputName(source.name), dataSource(&source) { if (source.type == Entry::SUBMENU) { Rule placeholder(Rule::OTHER_ENTRIES_PLACEHOLDER, currentPath, "*", true); placeholder.dataSource = pathFollower.getEntryByPath(currentPath); placeholder.dataSource_list = pathFollower.getListByPath(currentPath); this->subRules.push_front(placeholder); } for (std::list<Entry>::iterator iter = source.subEntries.begin(); iter != source.subEntries.end(); iter++) { std::list<std::string> currentPath_in_loop = currentPath; currentPath_in_loop.push_back(iter->name); bool currentPath_in_loop_is_blacklisted = false; for (std::list<std::list<std::string> >::const_iterator pti_iter = pathesToIgnore.begin(); pti_iter != pathesToIgnore.end(); pti_iter++) { if (*pti_iter == currentPath_in_loop) { currentPath_in_loop_is_blacklisted = true; break; } } if (!currentPath_in_loop_is_blacklisted){ this->subRules.push_back(Rule(*iter, isVisible, pathFollower, pathesToIgnore, currentPath_in_loop)); } } }
void RenderFullScreen::unwrapRenderer() { if (parent()) { RenderObject* child; while ((child = firstChild())) { // We have to clear the override size, because as a flexbox, we // may have set one on the child, and we don't want to leave that // lying around on the child. if (child->isBox()) toRenderBox(child)->clearOverrideSize(); child->removeFromParent(); parent()->addChild(child, this); parent()->setNeedsLayoutAndPrefWidthsRecalc(); } } if (placeholder()) placeholder()->removeFromParent(); removeFromParent(); document().setFullScreenRenderer(0); }
void RenderFullScreen::unwrapRenderer(bool& requiresRenderTreeRebuild) { requiresRenderTreeRebuild = false; if (parent()) { auto* child = firstChild(); // Things can get very complicated with anonymous block generation. // We can restore correctly without rebuild in simple cases only. // FIXME: We should have a mechanism for removing a block without reconstructing the tree. if (child != lastChild()) requiresRenderTreeRebuild = true; else if (child && child->isAnonymousBlock()) { auto& anonymousBlock = downcast<RenderBlock>(*child); if (anonymousBlock.firstChild() != anonymousBlock.lastChild()) requiresRenderTreeRebuild = true; } while ((child = firstChild())) { if (child->isAnonymousBlock() && !requiresRenderTreeRebuild) { if (auto* nonAnonymousChild = downcast<RenderBlock>(*child).firstChild()) child = nonAnonymousChild; else { child->removeFromParent(); child->destroy(); continue; } } // We have to clear the override size, because as a flexbox, we // may have set one on the child, and we don't want to leave that // lying around on the child. if (is<RenderBox>(*child)) downcast<RenderBox>(*child).clearOverrideSize(); child->removeFromParent(); parent()->addChild(child, this); parent()->setNeedsLayoutAndPrefWidthsRecalc(); } } if (placeholder()) placeholder()->removeFromParent(); removeFromParent(); document().setFullScreenRenderer(0); }
std::string SqlUtils::replacePlaceholder(std::string inputSql, std::string placeholderName, std::string placeholderValue) { std::string outSql(inputSql); std::string placeholder("${" + placeholderName + "}"); size_t startPos = outSql.find(placeholder); if (startPos == std::string::npos) { std::string errmsg("The placeholder "); errmsg.append(placeholderName); errmsg.append(" does not exist.\n"); throw std::runtime_error(errmsg); } outSql.erase(startPos, placeholder.length()); outSql.insert(startPos, placeholderValue); return outSql; }
void PhoneInput::paintEvent(QPaintEvent *e) { FlatInput::paintEvent(e); Painter p(this); QString t(text()); if (!pattern.isEmpty() && !t.isEmpty()) { QString ph = placeholder().mid(t.size()); if (!ph.isEmpty()) { p.setClipRect(rect()); QRect phRect(placeholderRect()); int tw = phFont()->m.width(t); if (tw < phRect.width()) { phRect.setLeft(phRect.left() + tw); phPrepare(p); p.drawText(phRect, ph, style::al_left); } } } }
NodeRef SynthTemplate::add_input(std::string name, sample default_value) { NodeRef placeholder(default_value); this->inputs[name] = placeholder.get(); return placeholder; }
/** * Converts characters so they look like they've been localized. * * Note: This leaves placeholder syntax untouched. */ std::u16string PseudoMethodAccent::text(const StringPiece16& source) { const char16_t* s = source.data(); std::u16string result; const size_t I = source.size(); bool lastspace = true; for (size_t i = 0; i < I; i++) { char16_t c = s[i]; if (c == '%') { // Placeholder syntax, no need to pseudolocalize std::u16string chunk; bool end = false; chunk.append(&c, 1); while (!end && i < I) { ++i; c = s[i]; chunk.append(&c, 1); if (isPossibleNormalPlaceholderEnd(c)) { end = true; } else if (c == 't') { ++i; c = s[i]; chunk.append(&c, 1); end = true; } } // Treat chunk as a placeholder unless it ends with %. result += ((c == '%') ? chunk : placeholder(chunk)); } else if (c == '<' || c == '&') { // html syntax, no need to pseudolocalize bool tag_closed = false; while (!tag_closed && i < I) { if (c == '&') { std::u16string escapeText; escapeText.append(&c, 1); bool end = false; size_t htmlCodePos = i; while (!end && htmlCodePos < I) { ++htmlCodePos; c = s[htmlCodePos]; escapeText.append(&c, 1); // Valid html code if (c == ';') { end = true; i = htmlCodePos; } // Wrong html code else if (!((c == '#' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')))) { end = true; } } result += escapeText; if (escapeText != u"<") { tag_closed = true; } continue; } if (c == '>') { tag_closed = true; result.append(&c, 1); continue; } result.append(&c, 1); i++; c = s[i]; } } else { // This is a pure text that should be pseudolocalized const char16_t* p = pseudolocalizeChar(c); if (p != nullptr) { result += p; } else { bool space = util::isspace16(c); if (lastspace && !space) { mWordCount++; } lastspace = space; result.append(&c, 1); } // Count only pseudolocalizable chars and delimiters mLength++; } } return result; }