[SVGDom] Add support for assorted absolute units
R=robertphillips@google.com,stephana@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2259473002 Review-Url: https://codereview.chromium.org/2259473002
This commit is contained in:
parent
0a61270f4b
commit
280e282d2a
@ -26,6 +26,13 @@ SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Multipliers for DPI-relative units.
|
||||
constexpr SkScalar kINMultiplier = 1.00f;
|
||||
constexpr SkScalar kPTMultiplier = kINMultiplier / 72.272f;
|
||||
constexpr SkScalar kPCMultiplier = kPTMultiplier * 12;
|
||||
constexpr SkScalar kMMMultiplier = kINMultiplier / 25.4f;
|
||||
constexpr SkScalar kCMMultiplier = kMMMultiplier * 10;
|
||||
|
||||
} // anonymous ns
|
||||
|
||||
SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
|
||||
@ -36,6 +43,16 @@ SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
|
||||
return l.value();
|
||||
case SkSVGLength::Unit::kPercentage:
|
||||
return l.value() * length_size_for_type(fViewport, t) / 100;
|
||||
case SkSVGLength::Unit::kCM:
|
||||
return l.value() * fDPI * kCMMultiplier;
|
||||
case SkSVGLength::Unit::kMM:
|
||||
return l.value() * fDPI * kMMMultiplier;
|
||||
case SkSVGLength::Unit::kIN:
|
||||
return l.value() * fDPI * kINMultiplier;
|
||||
case SkSVGLength::Unit::kPT:
|
||||
return l.value() * fDPI * kPTMultiplier;
|
||||
case SkSVGLength::Unit::kPC:
|
||||
return l.value() * fDPI * kPCMultiplier;
|
||||
default:
|
||||
SkDebugf("unsupported unit type: <%d>\n", l.unit());
|
||||
return 0;
|
||||
|
@ -20,7 +20,8 @@ class SkSVGLength;
|
||||
|
||||
class SkSVGLengthContext {
|
||||
public:
|
||||
SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {}
|
||||
SkSVGLengthContext(const SkSize& viewport, SkScalar dpi = 90)
|
||||
: fViewport(viewport), fDPI(dpi) {}
|
||||
|
||||
enum class LengthType {
|
||||
kHorizontal,
|
||||
@ -36,7 +37,8 @@ public:
|
||||
const SkSVGLength& w, const SkSVGLength& h) const;
|
||||
|
||||
private:
|
||||
SkSize fViewport;
|
||||
SkSize fViewport;
|
||||
SkScalar fDPI;
|
||||
};
|
||||
|
||||
struct SkSVGPresentationContext {
|
||||
|
Loading…
Reference in New Issue
Block a user