@armyc2.c5isr.renderer/mil-sym-ts-web 2.2.0

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 (170) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +57 -0
  3. package/buildNode.bat +2 -0
  4. package/buildWeb.bat +2 -0
  5. package/dist/C5Ren.d.ts +6970 -0
  6. package/dist/C5Ren.js +2 -0
  7. package/dist/C5Ren.js.map +1 -0
  8. package/dist/LICENSE +201 -0
  9. package/dist/README.md +57 -0
  10. package/dist/armyc2.c5isr.renderer-mil-sym-ts-web-2.2.0.tgz +0 -0
  11. package/dist/manifest.json +4 -0
  12. package/dist/package.json +16 -0
  13. package/index.ts +169 -0
  14. package/package.bak +50 -0
  15. package/package.json +40 -0
  16. package/package.node.json +43 -0
  17. package/package.pack.json +19 -0
  18. package/package.packWeb.json +16 -0
  19. package/package.web.json +40 -0
  20. package/src/main/ts/android/graphics/Bitmap.ts +7 -0
  21. package/src/main/ts/android/graphics/Paint.ts +26 -0
  22. package/src/main/ts/android/graphics/Path.ts +78 -0
  23. package/src/main/ts/android/graphics/PointF.ts +14 -0
  24. package/src/main/ts/android/graphics/Rect.ts +18 -0
  25. package/src/main/ts/android/graphics/RectF.ts +50 -0
  26. package/src/main/ts/android/graphics/Region.ts +36 -0
  27. package/src/main/ts/android/graphics/Typeface.ts +11 -0
  28. package/src/main/ts/armyc2/c5isr/JavaLineArray/BasicShapes.ts +99 -0
  29. package/src/main/ts/armyc2/c5isr/JavaLineArray/CChannelPoints2.ts +34 -0
  30. package/src/main/ts/armyc2/c5isr/JavaLineArray/CELineArray.ts +193 -0
  31. package/src/main/ts/armyc2/c5isr/JavaLineArray/Channels.ts +2971 -0
  32. package/src/main/ts/armyc2/c5isr/JavaLineArray/DISMSupport.ts +4008 -0
  33. package/src/main/ts/armyc2/c5isr/JavaLineArray/POINT2.ts +93 -0
  34. package/src/main/ts/armyc2/c5isr/JavaLineArray/Shape2.ts +89 -0
  35. package/src/main/ts/armyc2/c5isr/JavaLineArray/TacticalLines.ts +515 -0
  36. package/src/main/ts/armyc2/c5isr/JavaLineArray/arraysupport.ts +5403 -0
  37. package/src/main/ts/armyc2/c5isr/JavaLineArray/countsupport.ts +1084 -0
  38. package/src/main/ts/armyc2/c5isr/JavaLineArray/flot.ts +2173 -0
  39. package/src/main/ts/armyc2/c5isr/JavaLineArray/lineutility.ts +4934 -0
  40. package/src/main/ts/armyc2/c5isr/JavaLineArray/ref.ts +7 -0
  41. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/Modifier2.ts +5601 -0
  42. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/P1.ts +14 -0
  43. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/TGLight.ts +648 -0
  44. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsChannelUtility.ts +647 -0
  45. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsMETOC.ts +2994 -0
  46. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/clsUtility.ts +2663 -0
  47. package/src/main/ts/armyc2/c5isr/JavaTacticalRenderer/mdlGeodesic.ts +669 -0
  48. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsClipPolygon2.ts +971 -0
  49. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsClipQuad.ts +871 -0
  50. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsRenderer.ts +3507 -0
  51. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsRenderer2.ts +500 -0
  52. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtility.ts +1089 -0
  53. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtilityCPOF.ts +2656 -0
  54. package/src/main/ts/armyc2/c5isr/RenderMultipoints/clsUtilityGE.ts +1419 -0
  55. package/src/main/ts/armyc2/c5isr/data/genc.json +1407 -0
  56. package/src/main/ts/armyc2/c5isr/data/msd.json +17311 -0
  57. package/src/main/ts/armyc2/c5isr/data/mse.json +18500 -0
  58. package/src/main/ts/armyc2/c5isr/data/svgd.json +31214 -0
  59. package/src/main/ts/armyc2/c5isr/data/svge.json +30558 -0
  60. package/src/main/ts/armyc2/c5isr/graphics2d/AffineTransform.ts +10 -0
  61. package/src/main/ts/armyc2/c5isr/graphics2d/Area.ts +437 -0
  62. package/src/main/ts/armyc2/c5isr/graphics2d/BasicStroke.ts +429 -0
  63. package/src/main/ts/armyc2/c5isr/graphics2d/BasicTypes.ts +7 -0
  64. package/src/main/ts/armyc2/c5isr/graphics2d/BufferedImage.ts +35 -0
  65. package/src/main/ts/armyc2/c5isr/graphics2d/Font.ts +111 -0
  66. package/src/main/ts/armyc2/c5isr/graphics2d/FontMetrics.ts +29 -0
  67. package/src/main/ts/armyc2/c5isr/graphics2d/FontRenderContext.ts +18 -0
  68. package/src/main/ts/armyc2/c5isr/graphics2d/GeneralPath.ts +211 -0
  69. package/src/main/ts/armyc2/c5isr/graphics2d/Graphics2D.ts +80 -0
  70. package/src/main/ts/armyc2/c5isr/graphics2d/IPathIterator.ts +33 -0
  71. package/src/main/ts/armyc2/c5isr/graphics2d/ImageIO.ts +16 -0
  72. package/src/main/ts/armyc2/c5isr/graphics2d/Line2D.ts +726 -0
  73. package/src/main/ts/armyc2/c5isr/graphics2d/PathIterator.ts +141 -0
  74. package/src/main/ts/armyc2/c5isr/graphics2d/Point.ts +112 -0
  75. package/src/main/ts/armyc2/c5isr/graphics2d/Point2D.ts +261 -0
  76. package/src/main/ts/armyc2/c5isr/graphics2d/Polygon.ts +391 -0
  77. package/src/main/ts/armyc2/c5isr/graphics2d/Rectangle.ts +567 -0
  78. package/src/main/ts/armyc2/c5isr/graphics2d/Rectangle2D.ts +445 -0
  79. package/src/main/ts/armyc2/c5isr/graphics2d/Shape.ts +31 -0
  80. package/src/main/ts/armyc2/c5isr/graphics2d/Stroke.ts +18 -0
  81. package/src/main/ts/armyc2/c5isr/graphics2d/TextLayout.ts +45 -0
  82. package/src/main/ts/armyc2/c5isr/graphics2d/TexturePaint.ts +25 -0
  83. package/src/main/ts/armyc2/c5isr/renderer/IIconRenderer.ts +15 -0
  84. package/src/main/ts/armyc2/c5isr/renderer/IconRenderer.ts +22 -0
  85. package/src/main/ts/armyc2/c5isr/renderer/MilStdIconRenderer.ts +269 -0
  86. package/src/main/ts/armyc2/c5isr/renderer/ModifierRenderer.ts +9882 -0
  87. package/src/main/ts/armyc2/c5isr/renderer/PatternFillRenderer.ts +146 -0
  88. package/src/main/ts/armyc2/c5isr/renderer/SinglePointSVGRenderer.ts +1265 -0
  89. package/src/main/ts/armyc2/c5isr/renderer/shapes/arc.ts +64 -0
  90. package/src/main/ts/armyc2/c5isr/renderer/shapes/bcurve.ts +95 -0
  91. package/src/main/ts/armyc2/c5isr/renderer/shapes/ellipse.ts +93 -0
  92. package/src/main/ts/armyc2/c5isr/renderer/shapes/line.ts +114 -0
  93. package/src/main/ts/armyc2/c5isr/renderer/shapes/path.ts +555 -0
  94. package/src/main/ts/armyc2/c5isr/renderer/shapes/pathiterator.ts +62 -0
  95. package/src/main/ts/armyc2/c5isr/renderer/shapes/point.ts +120 -0
  96. package/src/main/ts/armyc2/c5isr/renderer/shapes/rectangle.ts +431 -0
  97. package/src/main/ts/armyc2/c5isr/renderer/shapes/roundedrectangle.ts +99 -0
  98. package/src/main/ts/armyc2/c5isr/renderer/shapes/types.ts +25 -0
  99. package/src/main/ts/armyc2/c5isr/renderer/shapes/utilities.ts +203 -0
  100. package/src/main/ts/armyc2/c5isr/renderer/utilities/AffiliationColors.ts +104 -0
  101. package/src/main/ts/armyc2/c5isr/renderer/utilities/Color.ts +481 -0
  102. package/src/main/ts/armyc2/c5isr/renderer/utilities/DistanceUnit.ts +40 -0
  103. package/src/main/ts/armyc2/c5isr/renderer/utilities/DrawRules.ts +1323 -0
  104. package/src/main/ts/armyc2/c5isr/renderer/utilities/EntityCode.ts +51 -0
  105. package/src/main/ts/armyc2/c5isr/renderer/utilities/ErrorLogger.ts +736 -0
  106. package/src/main/ts/armyc2/c5isr/renderer/utilities/GENCLookup.ts +106 -0
  107. package/src/main/ts/armyc2/c5isr/renderer/utilities/GeoPixelConversion3D.ts +84 -0
  108. package/src/main/ts/armyc2/c5isr/renderer/utilities/IMultiPointRenderer.ts +87 -0
  109. package/src/main/ts/armyc2/c5isr/renderer/utilities/IPointConversion.ts +34 -0
  110. package/src/main/ts/armyc2/c5isr/renderer/utilities/ImageInfo.ts +324 -0
  111. package/src/main/ts/armyc2/c5isr/renderer/utilities/LRUCache.ts +127 -0
  112. package/src/main/ts/armyc2/c5isr/renderer/utilities/LRUEntry.ts +18 -0
  113. package/src/main/ts/armyc2/c5isr/renderer/utilities/LogLevel.ts +111 -0
  114. package/src/main/ts/armyc2/c5isr/renderer/utilities/MODrawRules.ts +219 -0
  115. package/src/main/ts/armyc2/c5isr/renderer/utilities/MSInfo.ts +1008 -0
  116. package/src/main/ts/armyc2/c5isr/renderer/utilities/MSLookup.ts +882 -0
  117. package/src/main/ts/armyc2/c5isr/renderer/utilities/MilStdAttributes.ts +380 -0
  118. package/src/main/ts/armyc2/c5isr/renderer/utilities/MilStdSymbol.ts +797 -0
  119. package/src/main/ts/armyc2/c5isr/renderer/utilities/Modifiers.ts +1699 -0
  120. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConversion.ts +178 -0
  121. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConversionDummy.ts +45 -0
  122. package/src/main/ts/armyc2/c5isr/renderer/utilities/PointConverter3D.ts +126 -0
  123. package/src/main/ts/armyc2/c5isr/renderer/utilities/RectUtilities.ts +118 -0
  124. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererException.ts +11 -0
  125. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererSettings.ts +1201 -0
  126. package/src/main/ts/armyc2/c5isr/renderer/utilities/RendererUtilities.ts +591 -0
  127. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGInfo.ts +29 -0
  128. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGLookup.ts +753 -0
  129. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGSymbolInfo.ts +137 -0
  130. package/src/main/ts/armyc2/c5isr/renderer/utilities/SVGTextInfo.ts +438 -0
  131. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsChangedEvent.ts +19 -0
  132. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsChangedEventListener.ts +10 -0
  133. package/src/main/ts/armyc2/c5isr/renderer/utilities/SettingsEventListener.ts +5 -0
  134. package/src/main/ts/armyc2/c5isr/renderer/utilities/Shape2SVG.ts +404 -0
  135. package/src/main/ts/armyc2/c5isr/renderer/utilities/ShapeInfo.ts +525 -0
  136. package/src/main/ts/armyc2/c5isr/renderer/utilities/ShapeUtilities.ts +55 -0
  137. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolDimensionInfo.ts +36 -0
  138. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolID.ts +1055 -0
  139. package/src/main/ts/armyc2/c5isr/renderer/utilities/SymbolUtilities.ts +2085 -0
  140. package/src/main/ts/armyc2/c5isr/renderer/utilities/TextInfo.ts +157 -0
  141. package/src/main/ts/armyc2/c5isr/web/render/GeoPixelConversion.ts +86 -0
  142. package/src/main/ts/armyc2/c5isr/web/render/MultiPointHandler.ts +3798 -0
  143. package/src/main/ts/armyc2/c5isr/web/render/MultiPointHandlerSVG.ts +412 -0
  144. package/src/main/ts/armyc2/c5isr/web/render/PointConverter.ts +124 -0
  145. package/src/main/ts/armyc2/c5isr/web/render/SymbolModifiers.ts +26 -0
  146. package/src/main/ts/armyc2/c5isr/web/render/WebRenderer.ts +677 -0
  147. package/src/main/ts/armyc2/c5isr/web/render/utilities/JavaRendererUtilities.ts +484 -0
  148. package/src/main/ts/armyc2/c5isr/web/render/utilities/LineInfo.ts +62 -0
  149. package/src/main/ts/armyc2/c5isr/web/render/utilities/SymbolInfo.ts +46 -0
  150. package/src/main/ts/armyc2/c5isr/web/render/utilities/TextInfo.ts +51 -0
  151. package/src/main/ts/org/gavaghan/geodesy/Angle.ts +31 -0
  152. package/src/main/ts/org/gavaghan/geodesy/Ellipsoid.ts +71 -0
  153. package/src/main/ts/org/gavaghan/geodesy/GeodeticCalculator.ts +200 -0
  154. package/src/main/ts/org/gavaghan/geodesy/GeodeticCurve.ts +55 -0
  155. package/src/main/ts/org/gavaghan/geodesy/GeodeticMeasurement.ts +68 -0
  156. package/src/main/ts/org/gavaghan/geodesy/GlobalCoordinates.ts +103 -0
  157. package/src/main/ts/org/gavaghan/geodesy/GlobalPosition.ts +90 -0
  158. package/test/ExportSPImages.js +692 -0
  159. package/test/MPWW.html +556 -0
  160. package/test/MPWorker.js +318 -0
  161. package/test/SPWorker.js +233 -0
  162. package/test/SVGWW.html +363 -0
  163. package/test/singlePointTester3.html +751 -0
  164. package/tsconfig.json +54 -0
  165. package/typedoc.json +30 -0
  166. package/updateVersion.js +21 -0
  167. package/webpack.config.js +34 -0
  168. package/webpackn.config.js +28 -0
  169. package/webpackr.config.js +47 -0
  170. package/webpackw.config.js +23 -0
@@ -0,0 +1,137 @@
1
+ import { type int } from "../../graphics2d/BasicTypes";
2
+ import { Point } from "../../graphics2d/Point"
3
+ import { Point2D } from "../../graphics2d/Point2D"
4
+ import { Rectangle2D } from "../../graphics2d/Rectangle2D"
5
+ import { SymbolDimensionInfo } from "../../renderer/utilities/SymbolDimensionInfo"
6
+
7
+
8
+ export class SVGSymbolInfo implements SymbolDimensionInfo {
9
+
10
+ private _svg: string;
11
+ private _svgDataURI: string;
12
+
13
+ private _anchorX: int = 0;
14
+ private _anchorY: int = 0;
15
+ private _symbolBounds: Rectangle2D;
16
+ private _bounds: Rectangle2D;
17
+
18
+ public constructor(svg: string, anchorPoint: Point2D, symbolBounds: Rectangle2D, svgBounds: Rectangle2D) {
19
+ this._svg = svg;
20
+ this._anchorX = anchorPoint.getX() as int;
21
+ this._anchorY = anchorPoint.getY() as int;
22
+ this._symbolBounds = symbolBounds;
23
+ this._bounds = svgBounds;
24
+ }
25
+
26
+ // https://web.dev/articles/base64-encoding
27
+ // From https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem.
28
+ private bytesToBase64(bytes)
29
+ {
30
+ const binString = String.fromCodePoint(...bytes);
31
+ return btoa(binString);
32
+ }
33
+
34
+ private escapeChars(text:string):string
35
+ {
36
+ /*
37
+ Character XML encoding XML entity
38
+ \& \& \&\#38
39
+ \' \' \&\#30
40
+ \" \" \&\#34
41
+ \< \&lt; \&\#60
42
+ \> \&gt; \&\#62 //*/
43
+
44
+ let temp = text;
45
+
46
+ /*temp = temp.replace(/\n/g,"");
47
+ temp = temp.replace(/</g,"%3C");
48
+ temp = temp.replace(/>/g,"%3E");//*/
49
+
50
+ temp = temp.replace(/\n/g,"");
51
+ temp = temp.replace(/%/g,"%25");
52
+ temp = temp.replace(/#/g,"%23");//# to %23 for FF
53
+ temp = temp.replace(/"/g,"%22"); //" to %22 for EDGE
54
+ temp = temp.replace(/</g,"%3C");
55
+ temp = temp.replace(/=/g,"%3D")
56
+ temp = temp.replace(/>/g,"%3E");
57
+ temp = temp.replace(/\//g,"%2F");
58
+ temp = temp.replace(/\\/g,"%5C");
59
+ temp = temp.replace(/\[/g,"%5B");
60
+ temp = temp.replace(/\]/g,"%5D");
61
+ temp = temp.replace(/\^/g,"%5E");
62
+ temp = temp.replace(/\`/g,"%60");
63
+ temp = temp.replace(/\~/g,"%7E");
64
+ //temp = temp.replace(/\!/g,"%33");
65
+ temp = temp.replace(/\?/g,"%3F");
66
+ temp = temp.replace(/:/g,"%3A");
67
+ temp = temp.replace(/;/g,"%3B");
68
+ temp = temp.replace(/\@/g,"%40");
69
+ //temp = temp.replace(/\&/g,"%26");//&amp;
70
+ //temp = temp.replace(/\&/g,"&amp;");//&amp;//done in SVGTextInfo.toSVGElement AND Shape2SVG.ConvertForGroup
71
+ temp = temp.replace(/\{/g,"%7B");
72
+ temp = temp.replace(/\|/g,"%7C");
73
+ temp = temp.replace(/\}/g,"%7D");//*/
74
+
75
+ return temp;
76
+ }
77
+
78
+ public getSVGDataURI(): string {
79
+ if (this._svgDataURI == null)
80
+ {
81
+ //works with special characters but not in base64. Which should be fine.
82
+ //let temp:string = "data:image/svg+xml," + this.escapeChars(this._svg);
83
+
84
+ // https://web.dev/articles/base64-encoding
85
+ // From https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem.
86
+ //works with base64
87
+ let temp:string = "data:image/svg+xml;base64," + btoa(String.fromCodePoint(...new TextEncoder().encode(this._svg)))
88
+
89
+ this._svgDataURI = temp;
90
+ }
91
+ return this._svgDataURI;
92
+ }
93
+
94
+ public getSVG(): string { return this._svg; }
95
+
96
+ /**
97
+ * The x value the image should be centered on or the "anchor point".
98
+ * @return
99
+ */
100
+ public getSymbolCenterX(): int {
101
+ return this._anchorX;
102
+ }
103
+
104
+ /**
105
+ * The y value the image should be centered on or the "anchor point".
106
+ * @return
107
+ */
108
+ public getSymbolCenterY(): int {
109
+ return this._anchorY;
110
+ }
111
+
112
+ /**
113
+ * The point the image should be centered on or the "anchor point".
114
+ * @return
115
+ */
116
+ public getSymbolCenterPoint(): Point2D {
117
+ return new Point2D(this._anchorX, this._anchorY);
118
+ }
119
+
120
+ /**
121
+ * minimum bounding rectangle for the core symbol. Does
122
+ * not include modifiers, display or otherwise.
123
+ * @return
124
+ */
125
+ public getSymbolBounds(): Rectangle2D {
126
+ return this._symbolBounds;
127
+ }
128
+
129
+ /**
130
+ * Dimension of the entire image.
131
+ * @return
132
+ */
133
+
134
+ public getImageBounds(): Rectangle2D {
135
+ return new Rectangle2D(this._bounds.getX(), this._bounds.getY(), this._bounds.getWidth(), this._bounds.getHeight());
136
+ }
137
+ }
@@ -0,0 +1,438 @@
1
+ import { type double, type int } from "../../graphics2d/BasicTypes";
2
+
3
+ import { Font } from "../../graphics2d/Font"
4
+ import { Point2D } from "../../graphics2d/Point2D"
5
+ import { Rectangle2D } from "../../graphics2d/Rectangle2D"
6
+ import { RendererSettings } from "./RendererSettings"
7
+ import { ShapeUtilities } from "./ShapeUtilities";
8
+ import { RectUtilities } from "./RectUtilities";
9
+ import { Canvas, CanvasRenderingContext2D, createCanvas } from 'canvas';
10
+
11
+ /**
12
+ *
13
+ *
14
+ */
15
+ export class SVGTextInfo {
16
+ protected _text: string;
17
+ protected _font: string;
18
+ protected _fontName: string;
19
+ protected _fontSize: number = 0;
20
+ protected _fontStyle: string;
21
+ protected _location: Point2D;
22
+ protected _bounds: Rectangle2D;
23
+ protected _descent: double = 0;
24
+ protected _aboveBaseHeight: double = 0;
25
+ private justification: string = "start";
26
+ private angle: number = 0;
27
+ private alignmentBaseline: string = "alphabetic"
28
+
29
+ private isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
30
+ private isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
31
+ private OSCDefined = typeof OffscreenCanvasRenderingContext2D !== 'undefined';//web workers fail isBrowser test
32
+
33
+ public constructor(text: string, position: Point2D, font: Font, justification: string, angle: number);
34
+ public constructor(text: string, x: int, y: int, font: Font, context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null);
35
+ public constructor(text: string, x: int, y: int, font: string, context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null);
36
+ public constructor(text: string, x: int, y: int, fontName: string, fontSize:number, fontStyle:string, context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null);
37
+ public constructor(...args: unknown[])
38
+ {
39
+ let ctx:OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;
40
+ let tm:TextMetrics | any;
41
+ let top:number;
42
+ let left:number;
43
+ let width:number;
44
+ let height:number;
45
+ switch (args.length)
46
+ {
47
+ case 5:
48
+ {
49
+ if (args[1] instanceof Point2D) {
50
+ const [text, position, font, justification, angle] = args as [string, Point2D, Font, string, number];
51
+ let osc:any;//OffscreenCanvas | Canvas;
52
+ if(this.OSCDefined)
53
+ {
54
+ osc = new OffscreenCanvas(10, 10);
55
+ }
56
+ else
57
+ {
58
+ osc = createCanvas(10,10);
59
+ }
60
+ ctx = osc.getContext("2d");
61
+ ctx.font = font.toString();
62
+ this._font = font.toString();
63
+ this._fontName = font.getName();
64
+ this._fontSize = font.getSize();
65
+ this._fontStyle = font.getTypeString();
66
+ this._text = text;
67
+ tm = ctx.measureText(text);
68
+
69
+ if(this.OSCDefined)
70
+ top = position.y - (tm.fontBoundingBoxAscent + tm.fontBoundingBoxDescent) / 2;
71
+ else
72
+ {
73
+ top = position.y - (tm.emHeightAscent + tm.emHeightDescent) / 2;
74
+ }
75
+ left = position.x;
76
+ this._location = new Point2D(position.x, position.y);
77
+ this.justification = justification
78
+ this.angle = angle
79
+ this.alignmentBaseline = "middle"
80
+ } else {
81
+ const [text, x, y, font,context] = args as [string, number,number, any, OffscreenCanvasRenderingContext2D | any | null];
82
+
83
+ if(context == null)
84
+ {
85
+ let osc:any;//OffscreenCanvas | Canvas;
86
+ if(this.OSCDefined)
87
+ {
88
+ osc = new OffscreenCanvas(10,10);
89
+ }
90
+ else
91
+ osc = createCanvas(10,10);
92
+
93
+ ctx = osc.getContext("2d");
94
+ }
95
+ else
96
+ {
97
+ ctx = context;
98
+ }
99
+ if(typeof font === 'string')
100
+ {
101
+ ctx.font = font;
102
+ //Parse font string
103
+ let temp:string[] = font.split(' ');
104
+ this._fontStyle = temp[0];
105
+ this._fontSize = parseInt(temp[1].replace("px",""));
106
+ for(let i = 2; i < temp.length; i++)
107
+ {
108
+ if(i===2)
109
+ this._fontName = temp[i];
110
+ else
111
+ this._fontName += " " + temp[i];
112
+ }
113
+ }
114
+ else if(font instanceof Font)
115
+ {
116
+ ctx.font = font.toString();
117
+ this._fontName = font.getName();
118
+ this._fontSize = font.getSize();
119
+ this._fontStyle = font.getTypeString();
120
+ }
121
+
122
+ this._text = text;
123
+ tm = ctx.measureText(text);
124
+
125
+ if(tm.fontBoundingBoxAscent)
126
+ top = y - tm.fontBoundingBoxAscent;
127
+ else
128
+ {
129
+ top = y - tm.emHeightAscent;
130
+ }
131
+ left = x;
132
+ this._location = new Point2D(x, y);
133
+ }
134
+ break;
135
+ }
136
+ case 7:
137
+ {
138
+ const [text, x, y, fontName, fontSize, fontStyle, context] = args as [string, number, number, string, number, string, OffscreenCanvasRenderingContext2D | any | null];
139
+ if (arguments.length === 7)
140
+ {
141
+
142
+ if(context == null)
143
+ {
144
+ let osc:any;//OffscreenCanvas | Canvas;
145
+ if(this.OSCDefined)
146
+ {
147
+ osc = new OffscreenCanvas(10,10);
148
+ }
149
+ else
150
+ {
151
+ osc = createCanvas(10,10);
152
+ }
153
+ ctx = osc.getContext("2d");
154
+
155
+ this._font = fontStyle + " " + fontSize + "px " + fontName;
156
+ ctx.font = this._font
157
+ }
158
+ else
159
+ {
160
+ ctx = context;
161
+ }
162
+ this._fontStyle = fontStyle;
163
+ this._fontSize = fontSize;
164
+ this._fontName = fontName;
165
+ tm = ctx.measureText(text);
166
+
167
+ if(tm.fontBoundingBoxAscent)
168
+ top = y - tm.fontBoundingBoxAscent;
169
+ else
170
+ {
171
+ top = y - tm.emHeightAscent;
172
+ }
173
+ left = x;
174
+ this._location = new Point2D(x, y);
175
+ }
176
+ break;
177
+ }
178
+ }
179
+
180
+ width = tm.width;
181
+ width = tm.actualBoundingBoxRight + tm.actualBoundingBoxLeft;
182
+ if(this.OSCDefined)
183
+ height = tm.fontBoundingBoxDescent + tm.fontBoundingBoxAscent;
184
+ else
185
+ {
186
+ height = tm.emHeightDescent + tm.emHeightAscent;
187
+ }
188
+ if (this.justification == "middle")
189
+ left -= width / 2;
190
+ else if (this.justification == "end")
191
+ left -= width;
192
+
193
+ this._bounds = new Rectangle2D(left, top, width, height);
194
+
195
+ RectUtilities.grow(this._bounds,1);
196
+
197
+ if (this.angle != 0)
198
+ this._bounds = SVGTextInfo.getRotatedRectangleBounds(this._bounds, this.getLocation(), this.angle, this.justification);
199
+
200
+ if(this.OSCDefined)
201
+ {
202
+ this._descent = tm.fontBoundingBoxDescent;
203
+ this._aboveBaseHeight = tm.fontBoundingBoxAscent;
204
+ }
205
+ else
206
+ {
207
+ this._descent = tm.emHeightDescent;
208
+ this._aboveBaseHeight = tm.emHeightAscent;
209
+ }
210
+
211
+ /*console.log(this._text);
212
+ console.log(this._bounds);
213
+ console.log(tm);//*/
214
+ }
215
+
216
+ public setLocation(x: int, y: int): void {
217
+
218
+ this._bounds.setRect(x, y - this._aboveBaseHeight, this._bounds.getWidth(), this._bounds.getHeight());
219
+ RectUtilities.grow(this._bounds,1);
220
+ this._location.setLocation(x, y);
221
+ }
222
+
223
+ public getLocation(): Point2D {
224
+ return this._location;
225
+ }
226
+
227
+ public shift(x: int, y: int): void {
228
+ ShapeUtilities.offset(this._bounds, x, y);
229
+ ShapeUtilities.offset(this._location, x, y);
230
+ }
231
+
232
+ public getText(): string {
233
+ return this._text;
234
+ }
235
+
236
+ /**
237
+ * includes the descent
238
+ * @returns
239
+ */
240
+ public getTextBounds(): Rectangle2D {
241
+ return this._bounds;
242
+ }
243
+
244
+
245
+ public getTextOutlineBounds(): Rectangle2D {
246
+ let RS: RendererSettings = RendererSettings.getInstance();
247
+ let outlineOffset: int = RS.getTextOutlineWidth();
248
+ let bounds: Rectangle2D = this._bounds.clone() as Rectangle2D;
249
+
250
+ if (outlineOffset > 0) {
251
+ if (RS.getTextBackgroundMethod() === RendererSettings.TextBackgroundMethod_OUTLINE) {
252
+
253
+ ShapeUtilities.grow(bounds, outlineOffset / 2);
254
+ }
255
+
256
+ else {
257
+
258
+ ShapeUtilities.grow(bounds, outlineOffset);
259
+ }
260
+
261
+ }
262
+
263
+ return bounds;
264
+ }
265
+
266
+ public getDescent(): double {
267
+ return this._descent;
268
+ }
269
+
270
+ /**
271
+ *
272
+ * @param textColor hex color string
273
+ * @param outlineColor hex color string or null if no outline
274
+ * @param outlineWidth number value for outline width
275
+ * @param justification "start", "middle", or "end"
276
+ * @param svgFormat 0 - untouched, 1 - replace speacial characters with escape codes, 2 use encodeURIComponent (expensive)
277
+ * @returns
278
+ */
279
+ public toSVGElement(textColor:string, outlineColor:string | null, outlineWidth:number=0, justification: string=this.justification, svgFormat:number=0):string
280
+ {
281
+ let fill:string = textColor;
282
+ let stroke:string | null = outlineColor;
283
+ let strokeWidth:number = outlineWidth;
284
+ var format = 0;
285
+ if(svgFormat)
286
+ {
287
+ format = svgFormat;
288
+ }
289
+
290
+ let x:number = this._location.getX();
291
+ let y:number = this._location.getY();
292
+
293
+ var se: string;
294
+ if (this.angle == 0)
295
+ se = '<text x="' + x + '" y="' + y + '"';
296
+ else
297
+ se += '<text transform="translate(' + x + ',' + y + ') rotate(' + this.angle + ')"'
298
+ se += ' font-family="' + this._fontName + '"';
299
+ se += ' font-size="' + this._fontSize + 'px"';
300
+ se += ' font-weight="' + this._fontStyle + '"';
301
+ se += ' alignment-baseline="' + this.alignmentBaseline +'"';
302
+ se += ' stroke-miterlimit="3"';
303
+ se += ' text-anchor="' + justification + '"';
304
+
305
+ /*if(this._angle)
306
+ {
307
+ se += ' transform="rotate(' + this._angle + ' ' + this._location.getX() + ' ' + this._location.getY() + ')"';
308
+ }//*/
309
+
310
+ var seStroke = null,
311
+ seFill = null;
312
+
313
+ var text = this._text;
314
+ //catch special characters that break SVGs as base64 dataURIs
315
+ if(format === 1)
316
+ {
317
+ //got codes from: http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php
318
+ //and https://unicodelookup.com (use HTML code)
319
+ text = text.replace(/\&/g,"&amp;");
320
+ text = text.replace(/\</g,"&lt;");
321
+ text = text.replace(/\</g,"&gt;");
322
+ //text = text.replace(/\u2022/g,"&#x2022;");//echelon and ellipses dot
323
+ //text = text.replace(/\u25CF/g,"&#x2022;");//echelon and ellipses dot (black circle)
324
+ text = text.replace(/\u2022|\u25CF/g,"&#x2022;");//echelon and ellipses dot (black circle)
325
+ text = text.replace(/\u00D8/g,"&#216;");//Ø
326
+ text = text.replace(/\u00B0/g,"&#176;");//°
327
+ text = text.replace(/\u00B1/g,"&#x00B1;");//"RD" reinforce/reduced ±
328
+ }
329
+ else if(format === 2)
330
+ {
331
+ text = encodeURIComponent(text);
332
+ /*text = text.replace(/\&/g,"%24");
333
+ text = text.replace(/\</g,"%3C");
334
+ text = text.replace(/\</g,"%3E");
335
+ text = text.replace(/\u2022|\u25CF/g,"%95");//echelon and ellipses dot (black circle)
336
+ text = text.replace(/\u00B1/g,"%C2%B1");//"RD" reinforce/reduced +- symbol//*/
337
+ }
338
+
339
+ if(stroke != null && strokeWidth > 0)
340
+ {
341
+ if(format === 2)
342
+ seStroke = se + ' stroke="' + stroke.replace(/#/g,"%23") + '"';
343
+ else
344
+ seStroke = se + ' stroke="' + stroke + '"';
345
+ /*else
346
+ seStroke = se + ' stroke="' + stroke.replace(/#/g,"&#35;") + '"';*/
347
+
348
+ if(strokeWidth)
349
+ seStroke += ' stroke-width="' + (strokeWidth + 2) + '"';
350
+ seStroke += ' fill="none"';
351
+ seStroke += '>';
352
+ seStroke += text;
353
+ seStroke += '</text>';
354
+ }
355
+
356
+ if(fill != null)
357
+ {
358
+ if(format === 2)
359
+ seFill = se + ' fill="' + fill.replace(/#/g,"%23") + '"';
360
+ else
361
+ seFill = se + ' fill="' + fill + '"';
362
+ /*else
363
+ seFill = se + ' fill="' + fill.replace(/#/g,"%23") + '"';*/
364
+ seFill += '>';
365
+ seFill += text;
366
+ seFill += '</text>';
367
+ }
368
+
369
+ if(stroke && fill)
370
+ se = seStroke + seFill;
371
+ else if(fill)
372
+ se = seFill;
373
+ else
374
+ se = "";
375
+ return se;
376
+ }
377
+
378
+ /**
379
+ * @param {Rectangle2D} rectangle
380
+ * @returns {Rectangle2D}
381
+ */
382
+ static getRotatedRectangleBounds(rectangle: Rectangle2D, pivotPt: Point2D, angle: number, justification: string="middle"): Rectangle2D {
383
+ const textWidth = rectangle.getWidth()
384
+
385
+ if (justification == "start")
386
+ rectangle.x -= textWidth / 2;
387
+ else if (justification == "end")
388
+ rectangle.x += textWidth / 2;
389
+
390
+ let ptTL = new Point2D(rectangle.getMinX(), rectangle.getMinY())
391
+ let ptTR = new Point2D(rectangle.getMaxX(), rectangle.getMinY())
392
+ let ptBL = new Point2D(rectangle.getMinX(), rectangle.getMaxY())
393
+ let ptBR = new Point2D(rectangle.getMaxX(), rectangle.getMaxY())
394
+
395
+ SVGTextInfo.rotatePoint(ptTL, pivotPt, angle)
396
+ SVGTextInfo.rotatePoint(ptTR, pivotPt, angle)
397
+ SVGTextInfo.rotatePoint(ptBL, pivotPt, angle)
398
+ SVGTextInfo.rotatePoint(ptBR, pivotPt, angle)
399
+
400
+ rectangle = new Rectangle2D(ptTL.x, ptTL.y, 0, 0)
401
+ rectangle.add(ptTR.x, ptTR.y)
402
+ rectangle.add(ptBL.x, ptBL.y)
403
+ rectangle.add(ptBR.x, ptBR.y)
404
+
405
+ if (justification == "start") {
406
+ const s = Math.sin(angle * 2 * Math.PI / 360);
407
+ const c = Math.cos(angle * 2 * Math.PI / 360);
408
+ rectangle.x += textWidth / 2 * c;
409
+ rectangle.y += textWidth / 2 * s;
410
+ } else if (justification == "end") {
411
+ const s = Math.sin(angle * 2 * Math.PI / 360);
412
+ const c = Math.cos(angle * 2 * Math.PI / 360);
413
+ rectangle.x -= textWidth / 2 * c;
414
+ rectangle.y -= textWidth / 2 * s;
415
+ }
416
+
417
+ return rectangle;
418
+ }
419
+
420
+ /**
421
+ * @param {Point2D} pt Point to rotate
422
+ * @param {Point2D} pivotPt Point to rotate around
423
+ * @param {number} angle angle in degrees
424
+ */
425
+ static rotatePoint(pt: Point2D, pivotPt: Point2D, angle: number): void {
426
+ const s = Math.sin(- angle * 2 * Math.PI / 360);
427
+ const c = Math.cos(- angle * 2 * Math.PI / 360);
428
+
429
+ pt.x -= pivotPt.x;
430
+ pt.y -= pivotPt.y;
431
+
432
+ let xnew = pt.x * c - pt.y * s;
433
+ let ynew = pt.x * s + pt.y * c;
434
+
435
+ pt.x = xnew + pivotPt.x;
436
+ pt.y = ynew + pivotPt.y;
437
+ }
438
+ }
@@ -0,0 +1,19 @@
1
+ export class SettingsChangedEvent /*extends java.lang.Throwable*/ {
2
+
3
+ public static readonly EventType_CacheSizeChanged: string = "CACHE_CHANGED";
4
+ public static readonly EventType_CacheToggled: string = "CACHE_TOGGLED";
5
+ public static readonly EventType_FontChanged: string = "FONT_CHANGED";
6
+
7
+
8
+ private _EventType: string;
9
+ public constructor(eventType: string) {
10
+ if (eventType != null && eventType !== "") {
11
+ this._EventType = eventType;
12
+ }
13
+ }
14
+
15
+ public getEventType(): string {
16
+ return this._EventType;
17
+ }
18
+
19
+ }
@@ -0,0 +1,10 @@
1
+
2
+ import { SettingsChangedEvent } from "../../renderer/utilities/SettingsChangedEvent"
3
+
4
+ export interface SettingsChangedEventListener {
5
+
6
+ onSettingsChanged(sce: SettingsChangedEvent): void;
7
+
8
+ }
9
+
10
+
@@ -0,0 +1,5 @@
1
+
2
+
3
+ export interface SettingsEventListener {
4
+ SettingsEventChanged(type: string): void;
5
+ }