circuitscript 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +314 -190
  6. package/dist/cjs/execute.js +113 -115
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +12 -8
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +129 -125
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +2 -1
  16. package/dist/cjs/objects/ParamDefinition.js +120 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +40 -110
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +68 -2
  21. package/dist/cjs/visitor.js +214 -254
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +316 -193
  27. package/dist/esm/execute.mjs +115 -117
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +12 -8
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +131 -127
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +2 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +42 -112
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +64 -1
  42. package/dist/esm/visitor.mjs +216 -256
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +71 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +14 -10
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +21 -21
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  54. package/dist/types/objects/Frame.d.ts +2 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +6 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +15 -3
  61. package/package.json +7 -3
@@ -1,20 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassComponent = void 0;
3
+ exports.ModuleComponent = exports.ClassComponent = void 0;
4
4
  const draw_symbols_js_1 = require("../draw_symbols.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
+ const globals_js_1 = require("../globals.js");
7
8
  class ClassComponent {
8
- constructor(instanceName, numPins, className) {
9
+ constructor(instanceName, numPins) {
9
10
  this.parameters = new Map();
10
11
  this.pins = new Map();
11
12
  this.pinNets = new Map();
12
13
  this.pinWires = new Map();
14
+ this.pinsMaxPositions = {};
13
15
  this._copyID = null;
14
16
  this._copyFrom = null;
15
17
  this.arrangeProps = null;
16
18
  this.displayProp = null;
17
19
  this.widthProp = null;
20
+ this.heightProp = null;
18
21
  this.typeProp = null;
19
22
  this.copyProp = false;
20
23
  this.angleProp = 0;
@@ -22,12 +25,9 @@ class ClassComponent {
22
25
  this.wireOrientationAngle = 0;
23
26
  this.useWireOrientationAngle = true;
24
27
  this.didSetWireOrientationAngle = false;
25
- this.styles = {};
26
28
  this.assignedRefDes = null;
27
- this.moduleCounter = 0;
28
29
  this.instanceName = instanceName;
29
30
  this.numPins = numPins;
30
- this.className = className;
31
31
  }
32
32
  setupPins() {
33
33
  for (let i = 1; i < this.numPins + 1; i++) {
@@ -104,25 +104,26 @@ class ClassComponent {
104
104
  toString() {
105
105
  return this.instanceName;
106
106
  }
107
- static simple(instanceName, numPins, className) {
108
- const component = new ClassComponent(instanceName, numPins, className);
107
+ static simple(instanceName, numPins) {
108
+ const component = new ClassComponent(instanceName, numPins);
109
109
  component.setupPins();
110
110
  return component;
111
111
  }
112
112
  isEqual(other) {
113
113
  return this.instanceName === other.instanceName
114
114
  && this.numPins === other.numPins
115
- && this.className === other.className
116
115
  && this._copyID === other._copyID
117
116
  && this.arrangeProps === other.arrangeProps
118
- && this.displayProp === other.displayProp
117
+ && ((this.displayProp === null && other.displayProp === null)
118
+ ||
119
+ (this.displayProp !== null && other.displayProp !== null && this.displayProp.eq(other.displayProp)))
119
120
  && this.widthProp === other.widthProp
120
121
  && this.typeProp === other.typeProp
121
122
  && this._cachedPins === other._cachedPins
122
123
  && this._cachedParams === other._cachedParams;
123
124
  }
124
125
  clone() {
125
- const component = new ClassComponent(this.instanceName, this.numPins, this.className);
126
+ const component = new ClassComponent(this.instanceName, this.numPins);
126
127
  component._copyID = this._copyID;
127
128
  component.arrangeProps = this.arrangeProps;
128
129
  component.widthProp = this.widthProp;
@@ -130,17 +131,12 @@ class ClassComponent {
130
131
  component.angleProp = this.angleProp;
131
132
  component.followWireOrientationProp = this.followWireOrientationProp;
132
133
  component.useWireOrientationAngle = this.useWireOrientationAngle;
133
- if (this.displayProp) {
134
- if (typeof this.displayProp === "string") {
135
- component.displayProp = this.displayProp;
136
- }
137
- else if (this.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
138
- component.displayProp =
139
- this.displayProp.clone();
140
- }
134
+ if (this.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
135
+ component.displayProp =
136
+ this.displayProp.clone();
141
137
  }
142
138
  for (const [key, value] of this.parameters) {
143
- if (key === 'flipX' || key === 'flipY' || key === 'angle') {
139
+ if (key === globals_js_1.ParamKeys.flipX || key === globals_js_1.ParamKeys.flipY || key === globals_js_1.ParamKeys.angle) {
144
140
  continue;
145
141
  }
146
142
  component.parameters.set(key, value);
@@ -148,11 +144,15 @@ class ClassComponent {
148
144
  for (const [key, value] of this.pins) {
149
145
  component.pins.set(key, value);
150
146
  }
151
- for (const key in this.styles) {
152
- component.styles[key] = this.styles[key];
153
- }
154
147
  component.refreshCache();
155
148
  return component;
156
149
  }
157
150
  }
158
151
  exports.ClassComponent = ClassComponent;
152
+ class ModuleComponent extends ClassComponent {
153
+ constructor() {
154
+ super(...arguments);
155
+ this.moduleCounter = 0;
156
+ }
157
+ }
158
+ exports.ModuleComponent = ModuleComponent;
@@ -47,10 +47,7 @@ class ExecutionScope {
47
47
  }
48
48
  getNet(component, pin) {
49
49
  const result = this.findNet(component, pin);
50
- if (result) {
51
- return result[2];
52
- }
53
- return null;
50
+ return result ? result[2] : null;
54
51
  }
55
52
  setNet(component, pin, net) {
56
53
  const pair = this.findNet(component, pin);
@@ -113,6 +110,15 @@ class ExecutionScope {
113
110
  this.currentWireId = -1;
114
111
  this.currentFrameId = -1;
115
112
  }
113
+ setCurrent(component, pin = null) {
114
+ this.currentComponent = component;
115
+ if (component !== null) {
116
+ this.currentPin = (pin === null) ? component.getDefaultPin() : pin;
117
+ }
118
+ else {
119
+ this.currentPin = null;
120
+ }
121
+ }
116
122
  }
117
123
  exports.ExecutionScope = ExecutionScope;
118
124
  ExecutionScope.scopeId = 0;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FramePlotDirection = exports.FrameParamKeys = exports.Frame = void 0;
4
+ const globals_js_1 = require("../globals.js");
4
5
  class Frame {
5
- constructor(frameId, frameType) {
6
+ constructor(frameId, frameType = globals_js_1.FrameType.Frame) {
6
7
  this.parameters = new Map();
7
8
  this.frameId = frameId;
8
9
  this.frameType = frameType;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PercentageValue = exports.NumericValue = exports.ParamDefinition = void 0;
3
+ exports.NumberOperator = exports.WrappedNumber = exports.PercentageValue = exports.numeric = exports.NumericValue = exports.ParamDefinition = void 0;
4
+ const utils_1 = require("../utils");
5
+ const big_js_1 = require("big.js");
4
6
  class ParamDefinition {
5
7
  constructor(paramName, paramValue) {
6
8
  this.paramName = paramName;
@@ -9,8 +11,24 @@ class ParamDefinition {
9
11
  }
10
12
  exports.ParamDefinition = ParamDefinition;
11
13
  class NumericValue {
12
- constructor(value) {
14
+ constructor(value, prefix = 0) {
13
15
  this.value = value;
16
+ if (typeof value === 'string') {
17
+ const matches = value.match(/^([\d]+(?:.[\d]+)?)([\w]*)$/);
18
+ if (matches) {
19
+ this.valuePart = new big_js_1.Big(matches[1]);
20
+ this.prefixPart = (0, utils_1.getNumberExponential)(matches[2]);
21
+ }
22
+ else {
23
+ throw new Error("Invalid numeric value: " + value);
24
+ }
25
+ }
26
+ else {
27
+ this.valuePart = new big_js_1.Big(value);
28
+ this.prefixPart = prefix;
29
+ this.value = this.valuePart.toString()
30
+ + (0, utils_1.getNumberExponentialText)(prefix);
31
+ }
14
32
  }
15
33
  toString() {
16
34
  return 'numeric:' + this.value;
@@ -19,12 +37,59 @@ class NumericValue {
19
37
  if (typeof this.value === 'number') {
20
38
  return this.value.toString();
21
39
  }
22
- else if (typeof this.value === 'string') {
23
- return this.value;
40
+ else {
41
+ return this.valuePart.toString()
42
+ + (0, utils_1.getNumberExponentialText)(this.prefixPart);
43
+ }
44
+ }
45
+ toNumber() {
46
+ return this.toBigNumber().toNumber();
47
+ }
48
+ toBigNumber() {
49
+ return this.valuePart.mul(new big_js_1.Big(Math.pow(10, this.prefixPart)));
50
+ }
51
+ div(value) {
52
+ if (typeof value === 'number') {
53
+ value = numeric(value);
54
+ }
55
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().div(value.toBigNumber()));
56
+ }
57
+ mul(value) {
58
+ if (typeof value === 'number') {
59
+ value = numeric(value);
60
+ }
61
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().mul(value.toBigNumber()));
62
+ }
63
+ add(value) {
64
+ if (typeof value === 'number') {
65
+ value = numeric(value);
24
66
  }
67
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().add(value.toBigNumber()));
68
+ }
69
+ sub(value) {
70
+ if (typeof value === 'number') {
71
+ value = numeric(value);
72
+ }
73
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().sub(value.toBigNumber()));
74
+ }
75
+ mod(value) {
76
+ if (typeof value === 'number') {
77
+ value = numeric(value);
78
+ }
79
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().mod(value.toBigNumber()));
80
+ }
81
+ neg() {
82
+ return (0, utils_1.resolveToNumericValue)(this.toBigNumber().neg());
83
+ }
84
+ eq(value) {
85
+ return this.toBigNumber().eq(value.toBigNumber());
25
86
  }
26
87
  }
27
88
  exports.NumericValue = NumericValue;
89
+ function numeric(value) {
90
+ return new NumericValue(value);
91
+ }
92
+ exports.numeric = numeric;
28
93
  class PercentageValue {
29
94
  constructor(value) {
30
95
  this.value = value;
@@ -32,5 +97,56 @@ class PercentageValue {
32
97
  toString() {
33
98
  return this.value.toString();
34
99
  }
100
+ toNumber() {
101
+ return 0;
102
+ }
35
103
  }
36
104
  exports.PercentageValue = PercentageValue;
105
+ class WrappedNumber {
106
+ constructor(value) {
107
+ this.value = value;
108
+ }
109
+ toString() {
110
+ return this.value.toString();
111
+ }
112
+ toNumber() {
113
+ return this.value;
114
+ }
115
+ }
116
+ exports.WrappedNumber = WrappedNumber;
117
+ class NumberOperator {
118
+ prepare(value) {
119
+ if (typeof value === 'number') {
120
+ return new WrappedNumber(value);
121
+ }
122
+ else {
123
+ return value;
124
+ }
125
+ }
126
+ multiply(value1, value2) {
127
+ const big1 = new big_js_1.Big(value1.toNumber());
128
+ const big2 = new big_js_1.Big(value2.toNumber());
129
+ return (0, utils_1.resolveToNumericValue)(big1.mul(big2));
130
+ }
131
+ divide(value1, value2) {
132
+ const big1 = new big_js_1.Big(value1.toNumber());
133
+ const big2 = new big_js_1.Big(value2.toNumber());
134
+ return (0, utils_1.resolveToNumericValue)(big1.div(big2));
135
+ }
136
+ addition(value1, value2) {
137
+ const big1 = new big_js_1.Big(value1.toNumber());
138
+ const big2 = new big_js_1.Big(value2.toNumber());
139
+ return (0, utils_1.resolveToNumericValue)(big1.add(big2));
140
+ }
141
+ subtraction(value1, value2) {
142
+ const big1 = new big_js_1.Big(value1.toNumber());
143
+ const big2 = new big_js_1.Big(value2.toNumber());
144
+ return (0, utils_1.resolveToNumericValue)(big1.sub(big2));
145
+ }
146
+ modulus(value1, value2) {
147
+ const big1 = new big_js_1.Big(value1.toNumber());
148
+ const big2 = new big_js_1.Big(value2.toNumber());
149
+ return (0, utils_1.resolveToNumericValue)(big1.mod(big2));
150
+ }
151
+ }
152
+ exports.NumberOperator = NumberOperator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PinReference = exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
3
+ exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
4
4
  const PinTypes_js_1 = require("./PinTypes.js");
5
5
  class PinDefinition {
6
6
  constructor(id, idType, name, pinType = PinTypes_js_1.PinTypes.Any, altNames = []) {
@@ -26,6 +26,3 @@ var PortSide;
26
26
  PortSide["SOUTH"] = "SOUTH";
27
27
  PortSide["NORTH"] = "NORTH";
28
28
  })(PortSide || (exports.PortSide = PortSide = {}));
29
- class PinReference {
30
- }
31
- exports.PinReference = PinReference;
@@ -22,11 +22,12 @@ function createSvgCanvas() {
22
22
  (0, sizing_js_1.applyFontsToSVG)(canvas);
23
23
  return canvas;
24
24
  }
25
- function renderSheetsToSVG(sheetFrames) {
25
+ function renderSheetsToSVG(sheetFrames, logger) {
26
26
  const canvas = createSvgCanvas();
27
27
  sheetFrames.forEach((sheet, index) => {
28
28
  const sheetGroup = canvas.group();
29
- sheetGroup.id('sheet-' + index);
29
+ sheetGroup.id('sheet-' + index).addClass('sheet');
30
+ logger.add('rendering sheet: sheet-' + index);
30
31
  const { components, wires, junctions, mergedWires, frames, textObjects } = sheet;
31
32
  const allFrames = [sheet.frame, ...frames];
32
33
  let gridBounds = null;
@@ -35,6 +36,7 @@ function renderSheetsToSVG(sheetFrames) {
35
36
  let yOffset = 0;
36
37
  let sheetYOffset = 0;
37
38
  if (sheet.frame.frame) {
39
+ logger.add('drawing frame');
38
40
  const frameComponent = sheet.frame.frame.parameters
39
41
  .get(Frame_js_1.FrameParamKeys.SheetType);
40
42
  if (frameComponent) {
@@ -47,15 +49,18 @@ function renderSheetsToSVG(sheetFrames) {
47
49
  let widthMM = 0;
48
50
  let heightMM = 0;
49
51
  if (frameRects[0]) {
50
- originalWidthMM = (0, helpers_js_1.milsToMM)(frameRects[0].width);
51
- originalHeightMM = (0, helpers_js_1.milsToMM)(frameRects[0].height);
52
+ originalWidthMM = (0, helpers_js_1.milsToMM)(frameRects[0].width).toNumber();
53
+ originalHeightMM = (0, helpers_js_1.milsToMM)(frameRects[0].height).toNumber();
54
+ logger.add('first frame size: ' + originalWidthMM + ' ' + originalHeightMM);
52
55
  }
53
56
  if (frameRects[1]) {
54
- widthMM = (0, helpers_js_1.milsToMM)(frameRects[1].width);
55
- heightMM = (0, helpers_js_1.milsToMM)(frameRects[1].height);
57
+ widthMM = (0, helpers_js_1.milsToMM)(frameRects[1].width).toNumber();
58
+ heightMM = (0, helpers_js_1.milsToMM)(frameRects[1].height).toNumber();
59
+ logger.add('second frame size: ' + widthMM + ' ' + heightMM);
56
60
  }
57
61
  xOffset = (originalWidthMM - widthMM) / 2;
58
62
  yOffset = (originalHeightMM - heightMM) / 2;
63
+ logger.add('offset', xOffset, yOffset);
59
64
  sheetYOffset = index * (originalHeightMM + globals_js_1.defaultPageSpacingMM);
60
65
  gridBounds = {
61
66
  xmin: 0,
@@ -66,8 +71,10 @@ function renderSheetsToSVG(sheetFrames) {
66
71
  extendGrid = false;
67
72
  }
68
73
  }
69
- const sheetElements = sheetGroup.group();
70
- generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid);
74
+ logger.add('sheet contents offset: ' + xOffset + ' ' + yOffset);
75
+ logger.add('generating svg children in sheet');
76
+ const sheetElements = sheetGroup.group().addClass('sheet-elements');
77
+ generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid, logger);
71
78
  sheetElements.translate(xOffset, yOffset);
72
79
  sheetGroup.translate(0, sheetYOffset);
73
80
  });
@@ -114,16 +121,18 @@ function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoomScale =
114
121
  });
115
122
  }
116
123
  exports.generatePdfOutput = generatePdfOutput;
117
- function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid) {
124
+ function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid, logger) {
118
125
  const displayWireId = false;
119
126
  if (gridBounds === null) {
127
+ logger.add('get grid bounds');
120
128
  gridBounds = (0, layout_js_1.getBounds)(components, wires, junctions, frameObjects);
121
129
  }
122
- drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid);
130
+ logger.add('grid bounds', gridBounds.xmin, gridBounds.ymin, gridBounds.xmax, gridBounds.ymax);
131
+ drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid, logger);
123
132
  components.forEach(item => {
124
133
  const { x, y, width, height } = item;
125
134
  const symbolGroup = canvas.group();
126
- symbolGroup.translate(x, y);
135
+ symbolGroup.translate(x.toNumber(), y.toNumber());
127
136
  const { symbol = null } = item;
128
137
  if (symbol !== null && symbol) {
129
138
  const extra = {};
@@ -160,7 +169,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
160
169
  family: 'Arial',
161
170
  size: 50 * globals_js_1.fontDisplayScale,
162
171
  })
163
- .translate(wire.x + 5, wire.y + 5);
172
+ .translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
164
173
  });
165
174
  }
166
175
  const mergedWireGroup = canvas.group();
@@ -194,7 +203,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
194
203
  drawSheetFrameBorder(frameGroup, item);
195
204
  }
196
205
  else {
197
- if (borderWidth > 0) {
206
+ if (borderWidth.toNumber() > 0) {
198
207
  if (item.type === layout_js_1.RenderFrameType.Container) {
199
208
  strokeColor = '#111';
200
209
  }
@@ -206,24 +215,27 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
206
215
  }
207
216
  const tmpRect = frameGroup.rect(width, height)
208
217
  .fill('none')
209
- .stroke({ width: (0, helpers_js_1.milsToMM)(borderWidth), color: strokeColor });
210
- tmpRect.translate(item.x, item.y);
218
+ .stroke({
219
+ width: (0, helpers_js_1.milsToMM)(borderWidth).toNumber(),
220
+ color: strokeColor
221
+ });
222
+ tmpRect.translate(item.x.toNumber(), item.y.toNumber());
211
223
  }
212
224
  }
213
225
  });
214
226
  textObjects.forEach(item => {
215
227
  const { x, y, symbol } = item;
216
228
  const innerGroup = canvas.group();
217
- innerGroup.translate(x, y);
229
+ innerGroup.translate(x.toNumber(), y.toNumber());
218
230
  symbol.draw(innerGroup);
219
231
  });
220
- const originSize = (0, helpers_js_1.milsToMM)(10);
232
+ const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
221
233
  globals_js_1.RenderFlags.ShowOrigin && canvas.group().translate(0, 0)
222
234
  .circle(originSize)
223
235
  .translate(-originSize / 2, -originSize / 2)
224
236
  .stroke('none').fill('red');
225
237
  }
226
- function drawGrid(group, canvasSize, extendGrid) {
238
+ function drawGrid(group, canvasSize, extendGrid, logger) {
227
239
  const gridSize = globals_js_1.defaultGridSizeUnits;
228
240
  const { xmin, ymin, xmax, ymax } = canvasSize;
229
241
  const extraValue = extendGrid ? 1 : 0;
@@ -237,8 +249,12 @@ function drawGrid(group, canvasSize, extendGrid) {
237
249
  : (ymax - ymin);
238
250
  const numCols = Math.floor((gridEndX - gridStartX) / gridSize)
239
251
  + (extendGrid ? 1 : 0);
252
+ const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
253
+ globals_js_1.RenderFlags.ShowGridOrigin && group.circle(originSize)
254
+ .translate(-originSize / 2, -originSize / 2)
255
+ .stroke('none').fill('blue');
240
256
  const lines = [];
241
- const smallOffset = (0, helpers_js_1.milsToMM)(3);
257
+ const smallOffset = (0, helpers_js_1.milsToMM)(3).toNumber();
242
258
  const startY = gridStartY - smallOffset / 2;
243
259
  const endY = gridEndY + smallOffset;
244
260
  for (let i = 0; i < numCols; i++) {
@@ -246,12 +262,13 @@ function drawGrid(group, canvasSize, extendGrid) {
246
262
  lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
247
263
  }
248
264
  const strokeSize = (0, helpers_js_1.milsToMM)(3);
249
- group.path(lines.join(" "))
265
+ group.addClass('grid')
266
+ .path(lines.join(" "))
250
267
  .attr({
251
- 'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
268
+ 'stroke-dasharray': `${strokeSize.toNumber()},${gridSize - strokeSize.toNumber()}`,
252
269
  })
253
270
  .stroke({
254
- width: strokeSize,
271
+ width: strokeSize.toNumber(),
255
272
  color: '#000'
256
273
  });
257
274
  }
@@ -268,94 +285,7 @@ function drawSheetFrameBorder(frameGroup, frame) {
268
285
  symbol.draw(sheetFrameGroup);
269
286
  const offsetX = (0, helpers_js_1.milsToMM)(frameComponent.getParam('offset_x'));
270
287
  const offsetY = (0, helpers_js_1.milsToMM)(frameComponent.getParam('offset_y'));
271
- sheetFrameGroup.translate(-offsetX, -offsetY);
272
- }
273
- }
274
- }
275
- function drawSheetFrameBorderDirect(frameGroup, frame, borderWidth, strokeColor, width, height) {
276
- const commonStroke = {
277
- width: (0, helpers_js_1.milsToMM)(borderWidth),
278
- color: strokeColor
279
- };
280
- const commonFont = {
281
- family: globals_js_1.defaultFont,
282
- size: 50 * globals_js_1.fontDisplayScale,
283
- 'dominant-baseline': 'middle',
284
- 'text-anchor': 'middle',
285
- };
286
- let rows = 1;
287
- let columns = 1;
288
- let showGridReference = true;
289
- if (helpers_js_1.PaperGridReferences[frame.size]) {
290
- [rows, columns] = helpers_js_1.PaperGridReferences[frame.size];
291
- }
292
- else {
293
- showGridReference = false;
294
- }
295
- if (!showGridReference) {
296
- return;
297
- }
298
- const outerMargin = 2;
299
- const outerWidth = width + outerMargin * 2;
300
- const outerHeight = height + outerMargin * 2;
301
- const outerRect = frameGroup.rect(outerWidth, outerHeight)
302
- .fill('none')
303
- .stroke(commonStroke);
304
- outerRect.translate(frame.x - outerMargin, frame.y - outerMargin);
305
- const gridWidth = outerWidth / columns;
306
- const gridHeight = outerHeight / rows;
307
- const pathPoints = [];
308
- for (let i = 1; i < rows + 1; i++) {
309
- const lineStartX = frame.x - outerMargin;
310
- const lineStartX2 = frame.x - outerMargin + outerWidth - outerMargin;
311
- const lineY = frame.y - outerMargin + (gridHeight * i);
312
- if (i < rows) {
313
- pathPoints.push(...[
314
- "M", lineStartX, lineY, "L", lineStartX + outerMargin, lineY,
315
- "M", lineStartX2, lineY, "L", lineStartX2 + outerMargin, lineY
316
- ]);
288
+ sheetFrameGroup.translate(-offsetX.toNumber(), -offsetY.toNumber());
317
289
  }
318
- const displayValue = String.fromCharCode(i + 64);
319
- frameGroup.text(displayValue)
320
- .font(commonFont)
321
- .translate(lineStartX + outerMargin / 2, lineY - gridHeight / 2);
322
- frameGroup.text(displayValue)
323
- .font(commonFont)
324
- .translate(lineStartX2 + outerMargin / 2, lineY - gridHeight / 2);
325
- }
326
- for (let i = 1; i < columns + 1; i++) {
327
- const lineStartY = frame.y - outerMargin;
328
- const lineStartY2 = frame.y - outerMargin + outerHeight - outerMargin;
329
- const lineX = frame.x - outerMargin + (gridWidth * i);
330
- if (i < columns) {
331
- pathPoints.push(...[
332
- "M", lineX, lineStartY, "L", lineX, lineStartY + outerMargin,
333
- "M", lineX, lineStartY2, "L", lineX, lineStartY2 + outerMargin
334
- ]);
335
- }
336
- frameGroup.text(i.toString())
337
- .font(commonFont)
338
- .translate(lineX - gridWidth / 2, lineStartY + outerMargin / 2 + (0, helpers_js_1.milsToMM)(10));
339
- frameGroup.text(i.toString())
340
- .font(commonFont)
341
- .translate(lineX - gridWidth / 2, lineStartY2 + outerMargin / 2 + (0, helpers_js_1.milsToMM)(10));
342
- }
343
- frameGroup.path(pathPoints).stroke(commonStroke);
344
- const titleWidth = (0, helpers_js_1.milsToMM)(3000);
345
- const titleHeight = (0, helpers_js_1.milsToMM)(1000);
346
- const rowHeight = (0, helpers_js_1.milsToMM)(200);
347
- const points = [
348
- "M", width - titleWidth, height,
349
- "L", width - titleWidth, height - titleHeight,
350
- "L", width, height - titleHeight,
351
- "M", width - titleWidth, height - rowHeight,
352
- "L", width, height - rowHeight,
353
- "M", width - titleWidth, height - rowHeight * 2,
354
- "L", width, height - rowHeight * 2,
355
- "M", width - titleWidth, height - rowHeight * 3,
356
- "L", width, height - rowHeight * 3
357
- ];
358
- frameGroup.path(points).stroke(commonStroke).fill('none');
359
- if (frame.containsTitle) {
360
290
  }
361
291
  }
@@ -67,27 +67,53 @@ function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', an
67
67
  }
68
68
  const key = `${text}-${fontFamily}-${fontSize}-${fontWeight}-${anchor}-${vanchor}`;
69
69
  if (measureTextSizeCache[key] === undefined) {
70
- let dominantBaseline = 'hanging';
70
+ let dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
71
71
  switch (vanchor) {
72
72
  case geometry_js_1.VerticalAlign.Top:
73
- dominantBaseline = 'hanging';
73
+ dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
74
74
  break;
75
75
  case geometry_js_1.VerticalAlign.Middle:
76
- dominantBaseline = 'middle';
76
+ dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
77
77
  break;
78
78
  case geometry_js_1.VerticalAlign.Bottom:
79
- dominantBaseline = 'text-top';
79
+ dominantBaseline = geometry_js_1.VerticalAlignProp.TextTop;
80
+ break;
81
+ }
82
+ let useAnchor = geometry_js_1.HorizontalAlignProp.Start;
83
+ switch (anchor) {
84
+ case geometry_js_1.HorizontalAlign.Left:
85
+ useAnchor = geometry_js_1.HorizontalAlignProp.Start;
86
+ break;
87
+ case geometry_js_1.HorizontalAlign.Middle:
88
+ useAnchor = geometry_js_1.HorizontalAlignProp.Middle;
89
+ break;
90
+ case geometry_js_1.HorizontalAlign.Right:
91
+ useAnchor = geometry_js_1.HorizontalAlignProp.End;
80
92
  break;
81
93
  }
82
94
  fontFamily = globals_js_1.defaultFont;
83
95
  const tmpTextElement = MainCanvas.text(text).font({
84
96
  family: fontFamily,
85
97
  size: fontSize,
86
- anchor: anchor,
98
+ anchor: useAnchor,
87
99
  'dominant-baseline': dominantBaseline,
88
100
  weight: fontWeight,
89
- }).fill('#333');
90
- const textbox = tmpTextElement.bbox();
101
+ })
102
+ .attr("xml:space", "preserve")
103
+ .fill('#333');
104
+ let textbox = tmpTextElement.bbox();
105
+ const tmpTextBox = { ...textbox };
106
+ if (dominantBaseline === geometry_js_1.VerticalAlignProp.Hanging) {
107
+ tmpTextBox.y = textbox.cy - textbox.height;
108
+ tmpTextBox.y2 = tmpTextBox.y + textbox.height;
109
+ textbox = tmpTextBox;
110
+ }
111
+ else if (dominantBaseline === geometry_js_1.VerticalAlignProp.Central) {
112
+ tmpTextBox.y -= textbox.cy;
113
+ tmpTextBox.y2 -= textbox.cy;
114
+ tmpTextBox.cy = 0;
115
+ textbox = tmpTextBox;
116
+ }
91
117
  const { width, height } = textbox;
92
118
  tmpTextElement.remove();
93
119
  measureTextSizeCache[key] = {