Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(TS): Text SVG export mixin #8486

Merged
merged 19 commits into from
Dec 31, 2022
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ import './src/filters/gamma_filter.class'; // optional image_filters
import './src/filters/composed_filter.class'; // optional image_filters
import './src/filters/hue_rotation.class'; // optional image_filters
import './src/shapes/text.class'; // optional text
import './src/mixins/text.svg_export'; // optional svg
import './src/shapes/itext.class'; // optional itext
import './src/mixins/itext.svg_export'; // optional itext
import './src/shapes/textbox.class'; // optional textbox
import './src/controls'; // optional interaction
import './src/brushes'; // optional freedrawing
Expand Down
336 changes: 0 additions & 336 deletions src/mixins/itext.svg_export.ts

This file was deleted.

30 changes: 9 additions & 21 deletions src/mixins/object.svg_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import { uid } from '../util/internals/uid';
import { matrixToSVG } from '../util/misc/svgParsing';
import { toFixed } from '../util/misc/toFixed';

type SVGReviver = (markup: string) => string;
export type SVGReviver = (markup: string) => string;

/* _TO_SVG_START_ */

function getSvgColorString(prop: string, value?: any) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted to util and renamed to colorPropToSVG

/**
* Adobe Illustrator (at least CS5) is unable to render rgba()-based fill values
* we work around it by "moving" alpha channel into opacity attribute and setting fill's alpha to 1
* @param prop
* @param value
* @returns
*/
export function getSvgColorString(prop: string, value?: any) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now used by Text instead of _getFillAttributes

if (!value) {
return `${prop}: none; `;
} else if (value.toLive) {
Expand Down Expand Up @@ -170,25 +177,6 @@ export class FabricObjectSVGExportMixin {
return `${svgTransform}${additionalTransform}" `;
}

_setSVGBg(textBgRects: string[]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used by text, refactored into text svg export mixin

if (this.backgroundColor) {
const NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;
textBgRects.push(
'\t\t<rect ',
this._getFillAttributes(this.backgroundColor),
' x="',
toFixed(-this.width / 2, NUM_FRACTION_DIGITS),
'" y="',
toFixed(-this.height / 2, NUM_FRACTION_DIGITS),
'" width="',
toFixed(this.width, NUM_FRACTION_DIGITS),
'" height="',
toFixed(this.height, NUM_FRACTION_DIGITS),
'"></rect>\n'
);
}
}

/**
* Returns svg representation of an instance
* @param {SVGReviver} [reviver] Method for further parsing of svg representation.
Expand Down
Loading