2026_08_31
This commit is contained in:
commit
73015386e9
2320 files changed
+80291
No files matched your search
@@ -0,0 +1,110 @@
|
||||
|
||||
export abstract class DrawContainer {
|
||||
elements = new Map<number, DrawContainer | DrawElement>();
|
||||
|
||||
add(item: DrawContainer | DrawElement) {
|
||||
const elNr = this.elements.size
|
||||
this.elements.set(elNr, item);
|
||||
}
|
||||
|
||||
getElements() {
|
||||
return this.elements;
|
||||
}
|
||||
|
||||
abstract getChildString(xaml: boolean,deph:number):string;
|
||||
}
|
||||
|
||||
class Translate {
|
||||
dataXaml = new Map<string, {svg:string,xaml:string}>()
|
||||
constructor(private xaml?:boolean) {
|
||||
if(!xaml) this.xaml = false;
|
||||
this.dataXaml.set('color', {svg:'Color',xaml:'Color'});
|
||||
this.dataXaml.set('strokeWidth', {svg:'stroke-width',xaml:'StrokeThickness'});
|
||||
this.dataXaml.set('stroke', {svg:'stroke',xaml:'Stroke'});
|
||||
this.dataXaml.set('dasharray', {svg:'stroke-dasharray',xaml:'StrokeDashArray'});
|
||||
this.dataXaml.set('stroke-dasharray', {svg:'stroke-dasharray',xaml:'StrokeDashArray'});
|
||||
this.dataXaml.set('fill', {svg:'fill',xaml:'Fill'});
|
||||
this.dataXaml.set('opacity', {svg:'opacity',xaml:'opacity'});
|
||||
}
|
||||
|
||||
getAttribute(key: string, value: string | number): { key: string, value: string | number } {
|
||||
let t_key = this.dataXaml.get(key);
|
||||
|
||||
if(this.xaml && key==='fill' && value==='none') return {key:'ignore',value:''};
|
||||
//console.log(key,t_key)
|
||||
if (t_key && !this.xaml) return { key: t_key.svg, value: value };
|
||||
if (t_key && this.xaml) return { key: t_key.xaml, value: value };
|
||||
else return { key: key, value: value };
|
||||
}
|
||||
|
||||
setXaml(){
|
||||
this.xaml = true;
|
||||
}
|
||||
|
||||
setSvg(){
|
||||
this.xaml = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export abstract class DrawElement {
|
||||
attributes = new Map<string, string | number>();
|
||||
|
||||
constructor() { }
|
||||
|
||||
convertAttributesToString(values:Map<string, string|number>,xaml?: boolean, translate?: Translate) {
|
||||
translate = new Translate(xaml);
|
||||
|
||||
let str = '';
|
||||
let sep = ' ';
|
||||
for (const [key, paraValue] of values) {
|
||||
let attr = {key,value: paraValue};
|
||||
if (translate) attr = translate.getAttribute(attr.key, attr.value);
|
||||
|
||||
if(attr.key!=='ignore'){
|
||||
str += `${attr.key}="${attr.value}"${sep}`
|
||||
sep = ' ';
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
abstract drawSvg():string;
|
||||
abstract drawXaml():string;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
interface ElypI {
|
||||
x: number,
|
||||
y: number
|
||||
}
|
||||
|
||||
class Elipse extends DrawElement {
|
||||
constructor(name: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
getAttString(): string {
|
||||
return "att1=1";
|
||||
}
|
||||
|
||||
setAtrr(att: Partial<ElypI>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
drawSvg(): string {
|
||||
return 'not Supportet jet'
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawXaml(): string {
|
||||
return 'not Supportet jet'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import { DrawElement } from "./draw"
|
||||
|
||||
interface PropEllipse {
|
||||
cx: number
|
||||
cy: number
|
||||
rx: number
|
||||
ry: number
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
stroke?:string,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawEllipse extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private posAndSize: PropEllipse) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('strokeWidth', 1);
|
||||
this.attributes.set('stroke', "#000000");
|
||||
this.attributes.set('fill', 'none');
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.convertAttributesToString(this.attributes);
|
||||
const posSvg = this.getSvgPositions(this.posAndSize)
|
||||
const posStr = this.convertAttributesToString(posSvg);
|
||||
|
||||
const shape = this.drawElementSvg(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.convertAttributesToString(this.attributes, true);
|
||||
const posXaml = this.getXamlPositions(this.posAndSize)
|
||||
const posStr = this.convertAttributesToString(posXaml, true);
|
||||
|
||||
const shape = this.drawElementXaml(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(position: string, options: string) {
|
||||
return `<ellipse ${position} ${options}></ellipse>`
|
||||
}
|
||||
|
||||
drawElementXaml(position: string, options: string) {
|
||||
|
||||
return `<Ellipse ${position} ${options}></Ellipse>`
|
||||
|
||||
}
|
||||
|
||||
getSvgPositions(dim: PropEllipse) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('cx', dim.cx);
|
||||
retValue.set('cy', dim.cy);
|
||||
retValue.set('rx', dim.rx);
|
||||
retValue.set('ry', dim.ry);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
|
||||
getXamlPositions(dim: PropEllipse) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('Canvas.Left', dim.cx - dim.rx);
|
||||
retValue.set('Canvas.Top', dim.cy - dim.ry);
|
||||
retValue.set('Width', dim.rx * 2);
|
||||
retValue.set('Height', dim.ry * 2);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export function cal_rotation_dim(winkel: number, laenge: number, hoehe: number) {
|
||||
|
||||
let h = (Math.sin(Math.abs(winkel) * Math.PI / 180) * laenge) + (Math.cos(Math.abs(winkel) * Math.PI / 180) * hoehe);
|
||||
let w = ((Math.cos(Math.abs(winkel) * Math.PI / 180) * laenge) + (Math.sin(Math.abs(winkel) * Math.PI / 180) * hoehe));
|
||||
let d = Math.cos(Math.abs(winkel) * Math.PI / 180) * hoehe;
|
||||
let dw = Math.sin(Math.abs(winkel) * Math.PI / 180) * hoehe;
|
||||
|
||||
let offsetX = 0;
|
||||
let offsetY = h - d;
|
||||
if (winkel > 0) {
|
||||
offsetX = dw;
|
||||
offsetY = 0;
|
||||
}
|
||||
return { height: h, width: w, offsetX, offsetY };
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import { DrawContainer, DrawElement } from "./draw"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
interface PropDimGroup {
|
||||
x?: number,
|
||||
y?: number,
|
||||
rotate?: number
|
||||
}
|
||||
|
||||
|
||||
interface SvgOptionsGroup {
|
||||
rotate_winkel?: number
|
||||
rotate_posX?: number
|
||||
rotate_posY?: number
|
||||
translate_x?: number
|
||||
translate_y?: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawGroup extends DrawContainer {
|
||||
|
||||
attributes = new Map<string, string | number>();
|
||||
|
||||
constructor(private posDim: PropDimGroup) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptionsGroup>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getRotatetOption(): { winkel: number, posX: number, posY: number } | undefined {
|
||||
let winkel = this.attributes.get('rotate_winkel') as number;
|
||||
|
||||
let posX = this.attributes.get('rotate_posX') as number;
|
||||
let posY = this.attributes.get('rotate_posY') as number;
|
||||
if (!winkel) return undefined;
|
||||
let obj = {
|
||||
winkel: winkel,
|
||||
posX: posX ? posX : 0,
|
||||
posY: posY ? posY : 0
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
drawElementSvg(options?: string): { start: string, end: string } {
|
||||
// Check if Rotatate option set
|
||||
let rotate = this.getRotatetOption()
|
||||
let translate_x = this.attributes.get('translate_x') as number;
|
||||
let translate_y = this.attributes.get('translate_y') as number;
|
||||
let transformStr = ""
|
||||
if (translate_x || translate_y) {
|
||||
let x = translate_x ? translate_x : 0;
|
||||
let y = translate_y ? translate_y : 0;
|
||||
transformStr = `translate(${x} ${y}) `
|
||||
}
|
||||
|
||||
let rotateString = "";
|
||||
if (rotate) {
|
||||
rotateString = `transform="${transformStr}rotate(${rotate.winkel} ${rotate.posX} ${rotate.posY})"`
|
||||
}
|
||||
|
||||
return { start: `<g ${rotateString}>`, end: '</g>' }
|
||||
}
|
||||
|
||||
drawElementXaml(options?: string): { start: string, end: string } {
|
||||
let rotate = this.getRotatetOption()
|
||||
let translate_x = this.attributes.get('translate_x') as number;
|
||||
let translate_y = this.attributes.get('translate_y') as number;
|
||||
|
||||
let transformStr = "";
|
||||
if (rotate!=undefined || translate_x!=undefined || translate_y!=undefined) {
|
||||
let renderStart =
|
||||
` <Canvas.RenderTransformOrigin>0.5,0.5</Canvas.RenderTransformOrigin>
|
||||
<Canvas.RenderTransform><TransformGroup>`
|
||||
let renderEnd = `</TransformGroup></Canvas.RenderTransform>`
|
||||
|
||||
let rotateStr = rotate!=undefined ? `<RotateTransform Angle="${rotate.winkel}"/>`:""
|
||||
let translateXStr = translate_x!=undefined ? `X="${translate_x}"` : "";
|
||||
let translateYStr = translate_y!=undefined ? `Y="${translate_y}"` : "";
|
||||
let translateStr = translate_x!=undefined || translate_y != undefined ? ` <TranslateTransform ${translateXStr} ${translateYStr}/>`:"";
|
||||
transformStr = renderStart + rotateStr + translateStr + renderEnd;
|
||||
}
|
||||
/*
|
||||
` <Canvas.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform Angle="30"/>
|
||||
<TranslateTransform X="100" Y="50"/>
|
||||
</TransformGroup>
|
||||
</Canvas.RenderTransform>`
|
||||
*/
|
||||
return { start: `<Canvas> ${transformStr}`, end: '</Canvas>' }
|
||||
|
||||
}
|
||||
|
||||
getChildString(xaml: boolean, deph: number): string {
|
||||
|
||||
deph = deph + 1;
|
||||
|
||||
const reversedElements = Array.from(this.elements).reverse();
|
||||
let containerData = ''
|
||||
|
||||
for (const [key, value] of reversedElements) {
|
||||
let svgOfNextElement = ''
|
||||
|
||||
if (value instanceof DrawContainer) {
|
||||
svgOfNextElement = value.getChildString(xaml, deph)
|
||||
} else {
|
||||
const content = xaml ? value.drawXaml() : value.drawSvg();
|
||||
svgOfNextElement = "\t".repeat(deph) + content + '\n';
|
||||
}
|
||||
containerData += svgOfNextElement;
|
||||
}
|
||||
|
||||
const { start, end } = xaml ? this.drawElementXaml() : this.drawElementSvg();
|
||||
const group = "\t".repeat(deph - 1) + start + '\n' + containerData + "\t".repeat(deph - 1) + end + '\n'
|
||||
|
||||
return group;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
const group = (svg: string, options?: { x?: number, y?: number, rotate?: number }, xaml?: boolean) => {
|
||||
if (!options) options = { x: 0, y: 0, rotate: 0 };
|
||||
if (!options.x) options.x = 0;
|
||||
if (!options.y) options.y = 0;
|
||||
if (!options.rotate) options.rotate = 0;
|
||||
|
||||
let transform = '';
|
||||
let translate = '';
|
||||
let rotate = ''
|
||||
if (options.x > 0 || options.y > 0) translate = `translate(${options.x},${options.y})`
|
||||
if (options.rotate != 0) rotate = `rotate(${options.rotate} ${0} ${0})`
|
||||
if (options.x > 0 || options.y > 0 || options.rotate != 0) transform = `transform="${translate} ${rotate}"`
|
||||
|
||||
// XAML
|
||||
let x_left = `Left="${options.x}"`;
|
||||
let x_top = `Top="${options.y}"`;
|
||||
let x_rotate = '';
|
||||
if (options.rotate != 0) x_rotate =
|
||||
`
|
||||
<Canvas.RenderTransform>
|
||||
<RotateTransform Angle="${options.rotate}" CenterX="${0}" CenterY="${0}" />
|
||||
</Canvas.RenderTransform>`
|
||||
if (options.x > 0) x_left = ''
|
||||
|
||||
let group =
|
||||
`<g ${transform}>
|
||||
${svg}
|
||||
</g>`
|
||||
|
||||
let xgroup =
|
||||
`<Canvas ${x_left} ${x_top}>
|
||||
${svg} ${x_rotate}
|
||||
</Canvas>`
|
||||
|
||||
|
||||
if (xaml) return xgroup;
|
||||
return group;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { DrawContainer, DrawElement } from "./draw"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
interface PropDimHeader {
|
||||
lenght: number,
|
||||
height: number,
|
||||
}
|
||||
|
||||
|
||||
interface SvgOptionsGroup {
|
||||
dummy: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawHeader extends DrawContainer {
|
||||
|
||||
attributes = new Map<string,string|number>();
|
||||
length: number;
|
||||
height: number;
|
||||
constructor(dim: PropDimHeader) {
|
||||
super();
|
||||
this.length = dim.lenght;
|
||||
this.height = dim.height;
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptionsGroup>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
drawElementSvg(options?: string):{start:string,end:string} {
|
||||
const optionString = this.getSvgOptions(this.length,this.height);
|
||||
const start_z1 = `<?xml version="1.0" ?>\n`
|
||||
const start_z2 = `<svg xmlns="http://www.w3.org/2000/svg"\n`
|
||||
const start_z3 = `${optionString} >\n`
|
||||
return {start:start_z1+start_z2+start_z3, end:'</svg>'}
|
||||
}
|
||||
|
||||
drawElementXaml(options?: string):{start:string,end:string} {
|
||||
const optionString = this.getXamlOptions(this.length,this.height);
|
||||
const z1 = `<?xml version="1.0" ?>\n`
|
||||
const z2 =`<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">\n` // Stretch="Fill"
|
||||
const z3 =`<Canvas ${optionString}>\n`
|
||||
|
||||
return {start:z1+z2+z3,end:'</Canvas>\n</Viewbox>'}
|
||||
|
||||
}
|
||||
|
||||
getChildString(xaml: boolean,deph:number):string {
|
||||
|
||||
deph = deph +1;
|
||||
|
||||
const reversedElements = Array.from(this.elements).reverse();
|
||||
let containerData = ''
|
||||
|
||||
for (const [key, value] of reversedElements) {
|
||||
let svgOfNextElement = ''
|
||||
|
||||
if( value instanceof DrawContainer){
|
||||
svgOfNextElement = value.getChildString(xaml,deph)
|
||||
} else{
|
||||
const content = xaml?value.drawXaml():value.drawSvg();
|
||||
svgOfNextElement = "\t".repeat(deph) + content + '\n';
|
||||
}
|
||||
containerData += svgOfNextElement;
|
||||
}
|
||||
|
||||
const {start,end} = xaml ? this.drawElementXaml() : this.drawElementSvg();
|
||||
const group = "\t".repeat(deph-1) +start +'\n'+containerData+"\t".repeat(deph-1) + end + '\n'
|
||||
|
||||
return group;
|
||||
|
||||
}
|
||||
|
||||
getXamlOptions(length:number,height:number){
|
||||
return `Width="${length}" Height="${height}"`
|
||||
}
|
||||
|
||||
getSvgOptions(length:number,height:number){
|
||||
return `viewBox="0 0 ${length} ${height}"`
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { DrawElement } from "./draw"
|
||||
|
||||
/*
|
||||
const line = (data: PropLine, options?: SvgOptions, xaml?: boolean) => {
|
||||
let opt = { color: "#000000", storkWidth: 1, fill: 'none', dasharray: '' };
|
||||
if (options) opt = { ...opt, ...options };
|
||||
if (options && options.dasharray && !xaml) opt.dasharray = 'stroke-dasharray="' + options.dasharray + '"'
|
||||
if (options && options.dasharray && xaml) opt.dasharray = 'StrokeDashArray="' + options.dasharray + '"'.replace(',', ' ');
|
||||
|
||||
|
||||
|
||||
if(xaml) return xl;
|
||||
return l;
|
||||
}
|
||||
*/
|
||||
interface PropLine {
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawLine extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private posAndSize: PropLine) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('strokeWidth', 1);
|
||||
this.attributes.set('stroke', "#000000");
|
||||
this.attributes.set('fill', 'none');
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.convertAttributesToString(this.attributes);
|
||||
const posSvg = this.getSvgPositions(this.posAndSize)
|
||||
const posStr = this.convertAttributesToString(posSvg);
|
||||
|
||||
const shape = this.drawElementSvg(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.convertAttributesToString(this.attributes, true);
|
||||
const posXaml = this.getXamlPositions(this.posAndSize)
|
||||
const posStr = this.convertAttributesToString(posXaml, true);
|
||||
|
||||
const shape = this.drawElementXaml(posStr, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(position: string, options: string) {
|
||||
return `<line ${position} ${options}></line>`
|
||||
}
|
||||
|
||||
drawElementXaml(position: string, options: string) {
|
||||
|
||||
return `<Line ${position} ${options}></Line>`
|
||||
|
||||
}
|
||||
|
||||
getSvgPositions(dim: PropLine) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('x1', dim.x1);
|
||||
retValue.set('y1', dim.y1);
|
||||
retValue.set('x2', dim.x2);
|
||||
retValue.set('y2', dim.y2);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
|
||||
getXamlPositions(dim: PropLine) {
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('X1', dim.x1);
|
||||
retValue.set('Y1', dim.y1);
|
||||
retValue.set('X2', dim.x2);
|
||||
retValue.set('Y2', dim.y2);
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { DrawElement } from "./draw"
|
||||
import {PathCommand,} from './types/path.types';
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number,
|
||||
stroke?:string,
|
||||
strokeWidth?:number
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class DrawPath extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private pathCommands: PathCommand[]) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('strokeWidth', 2);
|
||||
this.attributes.set('stroke', "#202020");
|
||||
this.attributes.set('fill', 'none');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.convertAttributesToString(this.attributes);
|
||||
const path = this.getCmdString(false)
|
||||
|
||||
|
||||
const shape = this.drawElementSvg(path, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.convertAttributesToString(this.attributes, true);
|
||||
const path = this.getCmdString(true);
|
||||
const shape = this.drawElementXaml(path, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(pathCmd: string, options: string) {
|
||||
return `<path d="${pathCmd}" ${options}></path>`
|
||||
}
|
||||
|
||||
drawElementXaml(pathCmd: string, options: string) {
|
||||
|
||||
return `<Path Data="${pathCmd}" ${options}></Path>`
|
||||
|
||||
}
|
||||
|
||||
getCmdString(xaml: boolean = false) {
|
||||
const pathCmd = this.pathCommands.map(d => this.commandToString(d, xaml)).join(" ")
|
||||
|
||||
return pathCmd;
|
||||
|
||||
}
|
||||
|
||||
commandToString(cmd: PathCommand, xaml?: boolean): string {
|
||||
const prefix = cmd.relative && !xaml ? cmd.type.toLowerCase() : cmd.type;
|
||||
const separator = xaml ? "," : " ";
|
||||
switch (cmd.type) {
|
||||
case "M":
|
||||
case "L":
|
||||
return `${prefix} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "H":
|
||||
return `${prefix} ${cmd.x}`;
|
||||
|
||||
case "V":
|
||||
return `${prefix} ${cmd.y}`;
|
||||
|
||||
case "C":
|
||||
return `${prefix} ${cmd.x1}${separator}${cmd.y1} ${cmd.x2} ${cmd.y2} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "S":
|
||||
return `${prefix} ${cmd.x2} ${cmd.y2} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "Q":
|
||||
return `${prefix} ${cmd.x1} ${cmd.y1} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "T":
|
||||
return `${prefix} ${cmd.x} ${cmd.y}`;
|
||||
|
||||
case "A":
|
||||
return `${prefix} ${cmd.rx}${separator}${cmd.ry} ${cmd.xAxisRotation} ${cmd.largeArcFlag} ${cmd.sweepFlag} ${cmd.x}${separator}${cmd.y}`;
|
||||
|
||||
case "Z":
|
||||
return `${prefix}`;
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { DrawElement } from "./draw"
|
||||
|
||||
|
||||
interface PropText {
|
||||
x: number,
|
||||
y: number,
|
||||
text:string
|
||||
}
|
||||
|
||||
interface SvgOptions {
|
||||
color?: string
|
||||
storkWidth?: number,
|
||||
dasharray?: string,
|
||||
fill?: string,
|
||||
opacity?: number
|
||||
}
|
||||
|
||||
|
||||
export class DrawText extends DrawElement {
|
||||
|
||||
|
||||
|
||||
constructor(private posAndText: PropText) {
|
||||
super();
|
||||
|
||||
// Default Attribute
|
||||
this.attributes.set('stroke', "#000000");
|
||||
|
||||
}
|
||||
|
||||
|
||||
setAtrr(att: Partial<SvgOptions>) {
|
||||
Object.entries(att).forEach(([key, value]) => {
|
||||
this.attributes.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
drawSvg() {
|
||||
const paraStr = this.convertAttributesToString(this.attributes);
|
||||
const posSvg = this.getSvgPositions(this.posAndText)
|
||||
const posStr = this.convertAttributesToString(posSvg);
|
||||
|
||||
const shape = this.drawElementSvg(posStr,this.posAndText.text, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawXaml(): string {
|
||||
const paraStr = this.convertAttributesToString(this.attributes, true);
|
||||
//const posXaml = this.getXamlPositions(this.posAndText)
|
||||
//const posStr = this.convertAttributesToString(posXaml, true);
|
||||
|
||||
|
||||
const shape = this.drawElementXaml(this.posAndText.x,this.posAndText.y,this.posAndText.text, paraStr);
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
drawElementSvg(position: string,text:string, options: string) {
|
||||
return `<text ${position} ${options}>${text}</text>`
|
||||
}
|
||||
|
||||
drawElementXaml(posX:number,posY:number,text:string, options: string) {
|
||||
|
||||
return `<TextBlock Canvas.Left="${posX}"
|
||||
Canvas.Top="${posY}"
|
||||
Foreground="#000000"
|
||||
Text="${text}"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"/>`
|
||||
|
||||
}
|
||||
|
||||
getSvgPositions(dim: PropText) {
|
||||
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('x', dim.x);
|
||||
retValue.set('y', dim.y);
|
||||
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
|
||||
getXamlPositions(dim: PropText) {
|
||||
let retValue = new Map<string, number>();
|
||||
|
||||
retValue.set('X', dim.x);
|
||||
retValue.set('Y', dim.y);
|
||||
|
||||
|
||||
return retValue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,104 @@
|
||||
|
||||
|
||||
/** Basis-Typ: alle Commands haben ein Flag ob relativ oder absolut */
|
||||
export interface PathBaseCommand {
|
||||
/** true = relativer Befehl (kleiner Buchstabe), false/undefined = absolut */
|
||||
relative?: boolean;
|
||||
}
|
||||
|
||||
/** Move-To */
|
||||
export interface MoveToCommand extends PathBaseCommand {
|
||||
type: "M";
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Line-To */
|
||||
export interface LineToCommand extends PathBaseCommand {
|
||||
type: "L";
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Horizontal Line-To */
|
||||
export interface HorizontalLineToCommand extends PathBaseCommand {
|
||||
type: "H";
|
||||
x: number;
|
||||
}
|
||||
|
||||
/** Vertical Line-To */
|
||||
export interface VerticalLineToCommand extends PathBaseCommand {
|
||||
type: "V";
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Cubic Bézier Curve */
|
||||
export interface CubicBezierCommand extends PathBaseCommand {
|
||||
type: "C";
|
||||
x1: number; y1: number;
|
||||
x2: number; y2: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Smooth Cubic Bézier Curve */
|
||||
export interface SmoothCubicBezierCommand extends PathBaseCommand {
|
||||
type: "S";
|
||||
x2: number; y2: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Quadratic Bézier Curve */
|
||||
export interface QuadraticBezierCommand extends PathBaseCommand {
|
||||
type: "Q";
|
||||
x1: number; y1: number;
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Smooth Quadratic Bézier Curve */
|
||||
export interface SmoothQuadraticBezierCommand extends PathBaseCommand {
|
||||
type: "T";
|
||||
x: number; y: number;
|
||||
}
|
||||
|
||||
/** Elliptical Arc */
|
||||
export interface ArcCommand extends PathBaseCommand {
|
||||
type: "A";
|
||||
rx: number;
|
||||
ry: number;
|
||||
xAxisRotation: number;
|
||||
largeArcFlag: 0 | 1;
|
||||
sweepFlag: 0 | 1;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
/** Close Path */
|
||||
export interface ClosePathCommand extends PathBaseCommand {
|
||||
type: "Z";
|
||||
}
|
||||
|
||||
/** Union aller Path-Kommandos */
|
||||
export type PathCommand =
|
||||
| MoveToCommand
|
||||
| LineToCommand
|
||||
| HorizontalLineToCommand
|
||||
| VerticalLineToCommand
|
||||
| CubicBezierCommand
|
||||
| SmoothCubicBezierCommand
|
||||
| QuadraticBezierCommand
|
||||
| SmoothQuadraticBezierCommand
|
||||
| ArcCommand
|
||||
| ClosePathCommand;
|
||||
|
||||
/** Ein ganzer Pfad ist einfach eine Liste von Kommandos */
|
||||
export type SvgPath = PathCommand[];
|
||||
|
||||
|
||||
|
||||
|
||||
interface PropDimPath {
|
||||
cx: number
|
||||
cy: number
|
||||
rx: number
|
||||
ry: number
|
||||
}
|
||||
Reference in new issue
Block a user