BBox.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BBox = void 0;
  4. var lengths_js_1 = require("./lengths.js");
  5. var BBox = (function () {
  6. function BBox(def) {
  7. if (def === void 0) { def = { w: 0, h: -lengths_js_1.BIGDIMEN, d: -lengths_js_1.BIGDIMEN }; }
  8. this.w = def.w || 0;
  9. this.h = ('h' in def ? def.h : -lengths_js_1.BIGDIMEN);
  10. this.d = ('d' in def ? def.d : -lengths_js_1.BIGDIMEN);
  11. this.L = this.R = this.ic = this.sk = this.dx = 0;
  12. this.scale = this.rscale = 1;
  13. this.pwidth = '';
  14. }
  15. BBox.zero = function () {
  16. return new BBox({ h: 0, d: 0, w: 0 });
  17. };
  18. BBox.empty = function () {
  19. return new BBox();
  20. };
  21. BBox.prototype.empty = function () {
  22. this.w = 0;
  23. this.h = this.d = -lengths_js_1.BIGDIMEN;
  24. return this;
  25. };
  26. BBox.prototype.clean = function () {
  27. if (this.w === -lengths_js_1.BIGDIMEN)
  28. this.w = 0;
  29. if (this.h === -lengths_js_1.BIGDIMEN)
  30. this.h = 0;
  31. if (this.d === -lengths_js_1.BIGDIMEN)
  32. this.d = 0;
  33. };
  34. BBox.prototype.rescale = function (scale) {
  35. this.w *= scale;
  36. this.h *= scale;
  37. this.d *= scale;
  38. };
  39. BBox.prototype.combine = function (cbox, x, y) {
  40. if (x === void 0) { x = 0; }
  41. if (y === void 0) { y = 0; }
  42. var rscale = cbox.rscale;
  43. var w = x + rscale * (cbox.w + cbox.L + cbox.R);
  44. var h = y + rscale * cbox.h;
  45. var d = rscale * cbox.d - y;
  46. if (w > this.w)
  47. this.w = w;
  48. if (h > this.h)
  49. this.h = h;
  50. if (d > this.d)
  51. this.d = d;
  52. };
  53. BBox.prototype.append = function (cbox) {
  54. var scale = cbox.rscale;
  55. this.w += scale * (cbox.w + cbox.L + cbox.R);
  56. if (scale * cbox.h > this.h) {
  57. this.h = scale * cbox.h;
  58. }
  59. if (scale * cbox.d > this.d) {
  60. this.d = scale * cbox.d;
  61. }
  62. };
  63. BBox.prototype.updateFrom = function (cbox) {
  64. this.h = cbox.h;
  65. this.d = cbox.d;
  66. this.w = cbox.w;
  67. if (cbox.pwidth) {
  68. this.pwidth = cbox.pwidth;
  69. }
  70. };
  71. BBox.fullWidth = '100%';
  72. BBox.StyleAdjust = [
  73. ['borderTopWidth', 'h'],
  74. ['borderRightWidth', 'w'],
  75. ['borderBottomWidth', 'd'],
  76. ['borderLeftWidth', 'w', 0],
  77. ['paddingTop', 'h'],
  78. ['paddingRight', 'w'],
  79. ['paddingBottom', 'd'],
  80. ['paddingLeft', 'w', 0]
  81. ];
  82. return BBox;
  83. }());
  84. exports.BBox = BBox;
  85. //# sourceMappingURL=BBox.js.map