nehan
Version:
Html layout engine for paged-media written in Typescript
38 lines • 1.47 kB
JavaScript
import { Utils, LogicalSize, } from "./public-api";
export class PhysicalSize {
constructor(size) {
this.width = size.width;
this.height = size.height;
}
static load(element) {
const attr_width = element.getAttribute("width");
const attr_height = element.getAttribute("height");
const prop_width = attr_width || element.computedStyle.getPropertyValue("width");
const prop_height = attr_height || element.computedStyle.getPropertyValue("height");
const width = prop_width === "auto" ? 0 : Utils.atoi(attr_width || prop_width || "0");
const height = prop_height === "auto" ? 0 : Utils.atoi(attr_height || prop_height || "0");
return new PhysicalSize({ width: width, height: height });
}
getLogicalSize(writing_mode) {
return new LogicalSize({
measure: this.getMeasure(writing_mode),
extent: this.getExtent(writing_mode)
});
}
getExtent(writing_mode) {
return writing_mode.isTextVertical() ? this.width : this.height;
}
getMeasure(writing_mode) {
return writing_mode.isTextVertical() ? this.height : this.width;
}
getWidthPerHeight() {
return (this.height === 0) ? 1 : this.width / this.height;
}
isZero() {
return this.width === 0 && this.height === 0;
}
hasZero() {
return this.width === 0 || this.height === 0;
}
}
//# sourceMappingURL=physical-size.js.map