Use uniform, non-scaling-stroke.
rodzic
f64c600825
commit
75c68bb1fb
|
@ -49,7 +49,6 @@ type AttachmentChildren = JSX.Element | JSX.Element[];
|
||||||
|
|
||||||
type CreatureContextType = SvgSymbolContext & {
|
type CreatureContextType = SvgSymbolContext & {
|
||||||
attachmentScale: number;
|
attachmentScale: number;
|
||||||
cumulativeScale: number;
|
|
||||||
parent: SvgSymbolData | null;
|
parent: SvgSymbolData | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,7 +57,6 @@ const DEFAULT_ATTACHMENT_SCALE = 0.5;
|
||||||
const CreatureContext = React.createContext<CreatureContextType>({
|
const CreatureContext = React.createContext<CreatureContextType>({
|
||||||
...createSvgSymbolContext(),
|
...createSvgSymbolContext(),
|
||||||
attachmentScale: DEFAULT_ATTACHMENT_SCALE,
|
attachmentScale: DEFAULT_ATTACHMENT_SCALE,
|
||||||
cumulativeScale: 1,
|
|
||||||
parent: null,
|
parent: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,8 +96,6 @@ const CreatureSymbol: React.FC<CreatureSymbolProps> = (props) => {
|
||||||
value={{
|
value={{
|
||||||
...ctx,
|
...ctx,
|
||||||
parent: data,
|
parent: data,
|
||||||
cumulativeScale: ctx.attachmentScale * ctx.cumulativeScale,
|
|
||||||
strokeScale: 1 / ctx.cumulativeScale,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|
|
@ -3,9 +3,10 @@ import { SVGProps } from "react";
|
||||||
import { BBox } from "../vendor/bezier-js";
|
import { BBox } from "../vendor/bezier-js";
|
||||||
import { FILL_REPLACEMENT_COLOR, STROKE_REPLACEMENT_COLOR } from "./colors";
|
import { FILL_REPLACEMENT_COLOR, STROKE_REPLACEMENT_COLOR } from "./colors";
|
||||||
import { Specs } from "./specs";
|
import { Specs } from "./specs";
|
||||||
import { float } from "./util";
|
|
||||||
import { VisibleSpecs } from "./visible-specs";
|
import { VisibleSpecs } from "./visible-specs";
|
||||||
|
|
||||||
|
const DEFAULT_UNIFORM_STROKE_WIDTH = 1;
|
||||||
|
|
||||||
export type SvgSymbolData = {
|
export type SvgSymbolData = {
|
||||||
name: string;
|
name: string;
|
||||||
bbox: BBox;
|
bbox: BBox;
|
||||||
|
@ -29,15 +30,15 @@ export type SvgSymbolElement = (
|
||||||
export type SvgSymbolContext = {
|
export type SvgSymbolContext = {
|
||||||
stroke: string;
|
stroke: string;
|
||||||
fill: string;
|
fill: string;
|
||||||
strokeScale: number;
|
|
||||||
showSpecs: boolean;
|
showSpecs: boolean;
|
||||||
|
uniformStrokeWidth?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_CONTEXT: SvgSymbolContext = {
|
const DEFAULT_CONTEXT: SvgSymbolContext = {
|
||||||
stroke: "#000000",
|
stroke: "#000000",
|
||||||
fill: "#ffffff",
|
fill: "#ffffff",
|
||||||
strokeScale: 1,
|
|
||||||
showSpecs: false,
|
showSpecs: false,
|
||||||
|
uniformStrokeWidth: DEFAULT_UNIFORM_STROKE_WIDTH,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createSvgSymbolContext(
|
export function createSvgSymbolContext(
|
||||||
|
@ -68,16 +69,19 @@ function reactifySvgSymbolElement(
|
||||||
key: number
|
key: number
|
||||||
): JSX.Element {
|
): JSX.Element {
|
||||||
let { fill, stroke, strokeWidth } = el.props;
|
let { fill, stroke, strokeWidth } = el.props;
|
||||||
|
let vectorEffect;
|
||||||
fill = getColor(ctx, fill);
|
fill = getColor(ctx, fill);
|
||||||
stroke = getColor(ctx, stroke);
|
stroke = getColor(ctx, stroke);
|
||||||
if (strokeWidth !== undefined) {
|
if (strokeWidth !== undefined && ctx.uniformStrokeWidth) {
|
||||||
strokeWidth = float(strokeWidth) * ctx.strokeScale;
|
strokeWidth = ctx.uniformStrokeWidth;
|
||||||
|
vectorEffect = "non-scaling-stroke";
|
||||||
}
|
}
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
el.tagName,
|
el.tagName,
|
||||||
{
|
{
|
||||||
...el.props,
|
...el.props,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
|
vectorEffect,
|
||||||
strokeWidth,
|
strokeWidth,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
|
|
Ładowanie…
Reference in New Issue