123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.SSvgPaintEngine = void 0;
- var lib_1 = require("@saga-web/base/lib");
- var SPath2D_1 = require("../SPath2D");
- var __1 = require("..");
- var SSvgPaintEngine = (function (_super) {
- __extends(SSvgPaintEngine, _super);
- function SSvgPaintEngine(w, h) {
- var _this = _super.call(this) || this;
- _this._builder = new lib_1.SStringBuilder();
- _this.version = "1.1";
- _this.width = 0;
- _this.height = 0;
- _this.width = w;
- _this.height = h;
- _this._builder.append("<?xml version='1.0' standalone='no'?>");
- _this._builder.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
- _this._builder.append(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");
- _this._builder.append("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
- _this._builder.append("version=\"" + _this.version + "\" width=\"" + w + "\" height=\"" + h + "\">");
- return _this;
- }
- Object.defineProperty(SSvgPaintEngine.prototype, "type", {
- get: function () {
- return __1.SPaintEngineType.SVG;
- },
- enumerable: false,
- configurable: true
- });
- SSvgPaintEngine.prototype.toSvg = function () {
- return this._builder.toString("\n") + "</svg>\n";
- };
- SSvgPaintEngine.prototype.setClip = function (path) {
- };
- SSvgPaintEngine.prototype.clearRect = function (rect) { };
- SSvgPaintEngine.prototype.drawRect = function (rect) {
- this._builder.append("<rect x=\"" + rect.x + "\" y=\"" + rect.y + "\" width=\"" + rect.width + "\" height=\"" + rect.height + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawCircle = function (cx, cy, r) {
- this._builder.append("<circle cx=\"" + cx + "\" cy=\"" + cy + "\" r=\"" + r + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawEllipse = function (cx, cy, rx, ry) {
- this._builder.append("<ellipse cx=\"" + cx + "\" cy=\"" + cy + "\" rx=\"" + rx + "\" ry=\"" + ry + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawArc = function (x, y, width, height, startAngle, endAngle) {
- var path = SPath2D_1.SPath2D.arc(x, y, width, height, startAngle, endAngle);
- this._builder.append("<path d=\"" + path + "\" " + this.getStyle(false, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawChord = function (x, y, width, height, startAngle, endAngle) {
- var path = SPath2D_1.SPath2D.chord(x, y, width, height, startAngle, endAngle);
- this._builder.append("<path d=\"" + path + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawPie = function (x, y, width, height, startAngle, endAngle) {
- var path = SPath2D_1.SPath2D.pie(x, y, width, height, startAngle, endAngle);
- this._builder.append("<path d=\"" + path + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawLine = function (line) {
- this._builder.append("<line x1=\"" + line.x1 + "\" y1=\"" + line.y1 + "\" x2=\"" + line.x2 + "\" y2=\"" + line.y2 + "\" " + this.getStyle(false, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawPolyline = function (points) {
- this._builder.append("<polyline points=\"" + SSvgPaintEngine.pointsToStr(points) + "\" " + this.getStyle(false, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawPolygon = function (points) {
- this._builder.append("<polygon points=\"" + SSvgPaintEngine.pointsToStr(points) + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawPath = function (path) {
- this._builder.append("<path d=\"" + path.svgPath() + "\" " + this.getStyle(true, true, false) + " " + this.getSvgMatrix() + "/>");
- };
- SSvgPaintEngine.prototype.drawText = function (text, x, y, maxWidth) {
- this._builder.append("<text x=\"" + x + "\" y=\"" + y + "\" " + this.getStyle(true, false, true) + " " + this.getSvgMatrix() + ">" + text + "</text>>");
- };
- SSvgPaintEngine.prototype.drawImage = function (img, x, y, width, height) {
- };
- SSvgPaintEngine.prototype.textWidth = function (text) {
- return 0;
- };
- SSvgPaintEngine.prototype.changeFont = function (font) { };
- SSvgPaintEngine.prototype.getSvgMatrix = function () {
- return "transform=\"matrix(" + this.state.matrix.a + ", " + this.state.matrix.b + ", " + this.state.matrix.c + ", " + this.state.matrix.d + ", " + this.state.matrix.e + ", " + this.state.matrix.f + ")\"";
- };
- SSvgPaintEngine.pointsToStr = function (points) {
- var strBuilder = new lib_1.SStringBuilder();
- for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
- var p = points_1[_i];
- strBuilder.append(p.x + "," + p.y);
- }
- return strBuilder.toString(" ");
- };
- SSvgPaintEngine.prototype.getStyle = function (brush, pen, font) {
- if (brush === void 0) { brush = false; }
- if (pen === void 0) { pen = false; }
- if (font === void 0) { font = false; }
- var builder = new lib_1.SStringBuilder();
- builder.append('style="');
- if (pen) {
- builder.append("stroke:rgba(" + this.state.pen.color.red + ", " + this.state.pen.color.green + ", " + this.state.pen.color.blue + ", " + this.state.pen.color.alpha /
- 255.0 + ");");
- builder.append("stroke-width:" + this.state.pen.lineWidth + ";");
- }
- else {
- builder.append("stroke-width:0;");
- }
- if (brush) {
- builder.append("fill:rgba(" + this.state.brush.color.red + ", " + this.state.brush.color.green + ", " + this.state.brush.color.blue + ", " + this.state.brush.color
- .alpha / 255.0 + ");");
- }
- else {
- builder.append("fill:rgba(0,0,0,0);");
- }
- if (font) {
- builder.append("font-size:" + this.state.font.size + "px;");
- }
- builder.append('"');
- return builder.toString("");
- };
- return SSvgPaintEngine;
- }(__1.SPaintEngine));
- exports.SSvgPaintEngine = SSvgPaintEngine;
|