float SVGLength::value(const SVGElement* context, ExceptionCode& ec) const { switch (extractType(m_unit)) { case LengthTypeUnknown: ec = NOT_SUPPORTED_ERR; return 0; case LengthTypeNumber: return m_valueInSpecifiedUnits; case LengthTypePercentage: return convertValueFromPercentageToUserUnits(m_valueInSpecifiedUnits / 100, context, ec); case LengthTypeEMS: return convertValueFromEMSToUserUnits(m_valueInSpecifiedUnits, context, ec); case LengthTypeEXS: return convertValueFromEXSToUserUnits(m_valueInSpecifiedUnits, context, ec); case LengthTypePX: return m_valueInSpecifiedUnits; case LengthTypeCM: return m_valueInSpecifiedUnits / 2.54f * cssPixelsPerInch; case LengthTypeMM: return m_valueInSpecifiedUnits / 25.4f * cssPixelsPerInch; case LengthTypeIN: return m_valueInSpecifiedUnits * cssPixelsPerInch; case LengthTypePT: return m_valueInSpecifiedUnits / 72 * cssPixelsPerInch; case LengthTypePC: return m_valueInSpecifiedUnits / 6 * cssPixelsPerInch; } ASSERT_NOT_REACHED(); return 0; }
float SVGLength::valueAsPercentage() const { // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed if (extractType(m_unit) == LengthTypePercentage) return m_valueInSpecifiedUnits / 100; return m_valueInSpecifiedUnits; }
void SVGLength::setValue(float value, const SVGLengthContext& context, ExceptionState& exceptionState) { // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed if (extractType(m_unit) == LengthTypePercentage) value = value / 100; float convertedValue = context.convertValueFromUserUnits(value, extractMode(m_unit), extractType(m_unit), exceptionState); if (!exceptionState.hadException()) m_valueInSpecifiedUnits = convertedValue; }
ExceptionOr<void> SVGLengthValue::setValue(float value, const SVGLengthContext& context) { // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed if (extractType(m_unit) == LengthTypePercentage) value = value / 100; auto convertedValue = context.convertValueFromUserUnits(value, extractMode(m_unit), extractType(m_unit)); if (convertedValue.hasException()) return convertedValue.releaseException(); m_valueInSpecifiedUnits = convertedValue.releaseReturnValue(); return { }; }
float SVGLength::value() const { SVGLengthType type = extractType(m_unit); if (type == LengthTypeUnknown) return 0.0f; switch (type) { case LengthTypeNumber: return m_valueInSpecifiedUnits; case LengthTypePercentage: return SVGLength::PercentageOfViewport(m_valueInSpecifiedUnits / 100.0f, m_context, extractMode(m_unit)); case LengthTypeEMS: case LengthTypeEXS: { RenderStyle* style = 0; if (m_context && m_context->renderer()) style = m_context->renderer()->style(); if (style) { float useSize = style->fontSize(); ASSERT(useSize > 0); if (type == LengthTypeEMS) return m_valueInSpecifiedUnits * useSize; else { float xHeight = style->font().xHeight(); // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg // if this causes problems in real world cases maybe it would be best to remove this return m_valueInSpecifiedUnits * ceilf(xHeight); } } return 0.0f; } case LengthTypePX: return m_valueInSpecifiedUnits; case LengthTypeCM: return m_valueInSpecifiedUnits / 2.54f * cssPixelsPerInch; case LengthTypeMM: return m_valueInSpecifiedUnits / 25.4f * cssPixelsPerInch; case LengthTypeIN: return m_valueInSpecifiedUnits * cssPixelsPerInch; case LengthTypePT: return m_valueInSpecifiedUnits / 72.0f * cssPixelsPerInch; case LengthTypePC: return m_valueInSpecifiedUnits / 6.0f * cssPixelsPerInch; default: break; } ASSERT_NOT_REACHED(); return 0.0f; }
void SVGLength::setValue(float value, const SVGElement* context, ExceptionCode& ec) { switch (extractType(m_unit)) { case LengthTypeUnknown: ec = NOT_SUPPORTED_ERR; break; case LengthTypeNumber: m_valueInSpecifiedUnits = value; break; case LengthTypePercentage: { float result = convertValueFromUserUnitsToPercentage(value, context, ec); if (!ec) m_valueInSpecifiedUnits = result; break; } case LengthTypeEMS: { float result = convertValueFromUserUnitsToEMS(value, context, ec); if (!ec) m_valueInSpecifiedUnits = result; break; } case LengthTypeEXS: { float result = convertValueFromUserUnitsToEXS(value, context, ec); if (!ec) m_valueInSpecifiedUnits = result; break; } case LengthTypePX: m_valueInSpecifiedUnits = value; break; case LengthTypeCM: m_valueInSpecifiedUnits = value * 2.54f / cssPixelsPerInch; break; case LengthTypeMM: m_valueInSpecifiedUnits = value * 25.4f / cssPixelsPerInch; break; case LengthTypeIN: m_valueInSpecifiedUnits = value / cssPixelsPerInch; break; case LengthTypePT: m_valueInSpecifiedUnits = value * 72 / cssPixelsPerInch; break; case LengthTypePC: m_valueInSpecifiedUnits = value * 6 / cssPixelsPerInch; break; } }
std::vector<Type*> lowerJuliaArrayArguments(Function *OldFunc) { Module* M = OldFunc->getParent(); LLVMContext &context = M->getContext(); NamedMDNode* JuliaArgs = M->getOrInsertNamedMetadata("julia.args"); MDNode *node = JuliaArgs->getOperand(0); int operand = 0; std::vector<Type*> ArgTypes; for (Function::const_arg_iterator I = OldFunc->arg_begin(), E = OldFunc->arg_end(); I != E; ++I) { Type* argType = I->getType(); if (is_jl_array_type(argType)) { // Gets the type from custom metadata Value *value = node->getOperand(operand); if (MDString* mdstring = dyn_cast<MDString>(value)) { if (Type* type = extractType(context, mdstring->getString())) { ArgTypes.push_back(type); } else { errs() << "Could not extract type: "; mdstring->print(errs()); errs() << "\n"; exit(1); } } else { errs() << "Could not extract type: "; value->print(errs()); errs() << "\n"; exit(1); } } else { ArgTypes.push_back(I->getType()); } operand++; } return ArgTypes; }
void SVGLength::setValue(float value) { SVGLengthType type = extractType(m_unit); ASSERT(type != LengthTypeUnknown); switch (type) { case LengthTypeNumber: m_valueInSpecifiedUnits = value; break; case LengthTypePercentage: case LengthTypeEMS: case LengthTypeEXS: ASSERT_NOT_REACHED(); break; case LengthTypePX: m_valueInSpecifiedUnits = value; break; case LengthTypeCM: m_valueInSpecifiedUnits = value * 2.54f / cssPixelsPerInch; break; case LengthTypeMM: m_valueInSpecifiedUnits = value * 25.4f / cssPixelsPerInch; break; case LengthTypeIN: m_valueInSpecifiedUnits = value / cssPixelsPerInch; break; case LengthTypePT: m_valueInSpecifiedUnits = value * 72.0f / cssPixelsPerInch; break; case LengthTypePC: m_valueInSpecifiedUnits = value / 6.0f * cssPixelsPerInch; break; default: break; } }
String SVGLength::valueAsString() const { return String::number(m_valueInSpecifiedUnits) + lengthTypeToString(extractType(m_unit)); }
float SVGLength::value(const SVGLengthContext& context, ExceptionState& exceptionState) const { return context.convertValueToUserUnits(m_valueInSpecifiedUnits, extractMode(m_unit), extractType(m_unit), exceptionState); }
SVGLengthType SVGLength::unitType() const { return extractType(m_unit); }
void PipelineReaderJSON::parsePipeline(Json::Value& tree) { TagMap tags; std::vector<Stage*> inputs; Json::ArrayIndex last = tree.size() - 1; for (Json::ArrayIndex i = 0; i < tree.size(); ++i) { Json::Value& node = tree[i]; std::string filename; std::string tag; std::string type; std::vector<Stage*> specifiedInputs; Options options; // strings are assumed to be filenames if (node.isString()) { filename = node.asString(); } else { type = extractType(node); filename = extractFilename(node); tag = extractTag(node, tags); specifiedInputs = extractInputs(node, tags); if (!specifiedInputs.empty()) inputs = specifiedInputs; options = extractOptions(node); } Stage *s = nullptr; // The type is inferred from a filename as a reader if it's not // the last stage or if there's only one. if ((type.empty() && (i == 0 || i != last)) || Utils::startsWith(type, "readers.")) { StringList files = FileUtils::glob(filename); if (files.empty()) files.push_back(filename); for (const std::string& path : files) { StageCreationOptions ops { path, type, nullptr, options, tag }; s = &m_manager.makeReader(ops); if (specifiedInputs.size()) throw pdal_error("JSON pipeline: Inputs not permitted for " " reader: '" + path + "'."); inputs.push_back(s); } } else if (type.empty() || Utils::startsWith(type, "writers.")) { StageCreationOptions ops { filename, type, nullptr, options, tag }; s = &m_manager.makeWriter(ops); for (Stage *ts : inputs) s->setInput(*ts); inputs.clear(); } else { if (filename.size()) options.add("filename", filename); StageCreationOptions ops { "", type, nullptr, options, tag }; s = &m_manager.makeFilter(ops); for (Stage *ts : inputs) s->setInput(*ts); inputs.clear(); inputs.push_back(s); } // 's' should be valid at this point. makeXXX will throw if the stage // couldn't be constructed. if (tag.size()) tags[tag] = s; } }
ExceptionOr<float> SVGLengthValue::valueForBindings(const SVGLengthContext& context) const { return context.convertValueToUserUnits(m_valueInSpecifiedUnits, extractMode(m_unit), extractType(m_unit)); }