本文整理汇总了TypeScript中app/scripts/common.Matrix.translation方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Matrix.translation方法的具体用法?TypeScript Matrix.translation怎么用?TypeScript Matrix.translation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/scripts/common.Matrix
的用法示例。
在下文中一共展示了Matrix.translation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fromPathOpString
export function fromPathOpString(pathString: string, pathOpsString: string) {
const A = pathOpsString.split(' ');
const mutator = new Path(pathString).mutate();
for (let i = 0; i < A.length; i++) {
const op = A[i] as PathOp;
switch (op) {
case 'RV': // Reverse.
mutator.reverseSubPath(+A[i + 1]);
i += 1;
break;
case 'SB': // Shift back.
mutator.shiftSubPathBack(+A[i + 1]);
i += 1;
break;
case 'SF': // Shift forward.
mutator.shiftSubPathForward(+A[i + 1]);
i += 1;
break;
case 'S': // Split.
const subIdx = +A[i + 1];
const cmdIdx = +A[i + 2];
const args = [+A[i + 3]];
i += 3;
while (!isNaN(+A[i + 1]) && i < A.length) {
args.push(+A[i + 1]);
i++;
}
mutator.splitCommand(subIdx, cmdIdx, ...args);
break;
case 'SIH': // Split in half.
mutator.splitCommandInHalf(+A[i + 1], +A[i + 2]);
i += 2;
break;
case 'US': // Unsplit.
mutator.unsplitCommand(+A[i + 1], +A[i + 2]);
i += 2;
break;
case 'CV': // Convert.
mutator.convertCommand(+A[i + 1], +A[i + 2], A[i + 3] as SvgChar);
i += 3;
break;
case 'UCV': // Unconvert.
mutator.unconvertSubPath(+A[i + 1]);
i += 1;
break;
case 'RT': // Revert.
mutator.revert();
break;
case 'M': // Move subpath.
mutator.moveSubPath(+A[i + 1], +A[i + 2]);
i += 2;
break;
case 'AC': // Add collapsing sub path.
mutator.addCollapsingSubPath({ x: +A[i + 1], y: +A[i + 2] }, +A[i + 3]);
i += 3;
break;
case 'DC': // Delete collapsing sub paths.
mutator.deleteCollapsingSubPaths();
break;
case 'SSSP': // Split stroked sub path.
mutator.splitStrokedSubPath(+A[i + 1], +A[i + 2]);
i += 2;
break;
case 'SFSP': // Split filled sub path.
mutator.splitFilledSubPath(+A[i + 1], +A[i + 2], +A[i + 3]);
i += 3;
break;
case 'DFSP': // Delete filled sub path.
mutator.deleteFilledSubPath(+A[i + 1]);
i += 1;
break;
case 'DFSPS': // Delete filled subpath segment.
mutator.deleteFilledSubPathSegment(+A[i + 1], +A[i + 2]);
i += 2;
break;
case 'DSSP': // Delete stroked sub path.
mutator.deleteStrokedSubPath(+A[i + 1]);
i += 1;
break;
case 'T': // Transform.
const isTransformOpFn = (token: string) => {
token = (token || '').toLowerCase();
return new Set(['scale', 'rotate', 'translate']).has(token);
};
while (isTransformOpFn(A[i + 1])) {
const transformOp = A[i + 1];
let matrix: Matrix;
switch (transformOp) {
case 'scale':
matrix = Matrix.scaling(+A[i + 2], +A[i + 3]);
i += 3;
break;
case 'rotate':
matrix = Matrix.rotation(+A[i + 2]);
i += 2;
break;
case 'translate':
matrix = Matrix.translation(+A[i + 2], +A[i + 3]);
i += 3;
break;
//.........这里部分代码省略.........
示例2: loadVectorLayerFromSvgString
//.........这里部分代码省略.........
simpleAttrFn('fill', 'fillColor');
simpleAttrFn('fill-opacity', 'fillAlpha');
simpleAttrFn('fill-rule', 'fillType');
// Set the default values as specified by the SVG spec. Note that some of these default
// values are different than the default values used by VectorDrawables.
const fillColor =
'fillColor' in attrMap ? ColorUtil.svgToAndroidColor(attrMap['fillColor']) : '#000';
const strokeColor =
'strokeColor' in attrMap ? ColorUtil.svgToAndroidColor(attrMap['strokeColor']) : undefined;
const fillAlpha = 'fillAlpha' in attrMap ? Number(attrMap['fillAlpha']) : 1;
let strokeWidth = 'strokeWidth' in attrMap ? Number(attrMap['strokeWidth']) : 1;
const strokeAlpha = 'strokeAlpha' in attrMap ? Number(attrMap['strokeAlpha']) : 1;
const strokeLinecap: StrokeLineCap =
'strokeLinecap' in attrMap ? attrMap['strokeLinecap'] : 'butt';
const strokeLinejoin: StrokeLineJoin =
'strokeLinejoin' in attrMap ? attrMap['strokeLinecap'] : 'miter';
const strokeMiterLimit =
'strokeMiterLimit' in attrMap ? Number(attrMap['strokeMiterLimit']) : 4;
const fillRuleToFillTypeFn = (fillRule: string) => {
return fillRule === 'evenodd' ? 'evenOdd' : 'nonZero';
};
const fillType: FillType =
'fillType' in attrMap ? fillRuleToFillTypeFn(attrMap['fillType']) : 'nonZero';
let pathData = new Path(path);
if (transforms.length) {
pathData = new Path(
pathData
.mutate()
.transform(flattenedTransforms)
.build()
.getPathString(),
);
strokeWidth = MathUtil.round(strokeWidth * flattenedTransforms.getScaleFactor());
}
// TODO: make best effort attempt to restore trimPath{Start,End,Offset}
return maybeWrapClipPathInGroupFn(
new PathLayer({
id: _.uniqueId(),
name: makeFinalNodeIdFn(node.getAttribute('id'), 'path'),
children: [],
pathData,
fillColor,
fillAlpha,
strokeColor,
strokeAlpha,
strokeWidth,
strokeLinecap,
strokeLinejoin,
strokeMiterLimit,
fillType,
}),
);
}
if (node.childNodes) {
const children: Layer[] = [];
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes.item(i) as Element;
const layer = nodeToLayerFn(child, transforms);
if (layer) {
children.push(layer);
}
}
return maybeWrapClipPathInGroupFn(
new GroupLayer({
id: _.uniqueId(),
name: makeFinalNodeIdFn(node.getAttribute('id'), 'group'),
children,
}),
);
}
return undefined;
};
const toNumberFn = (num: any) => (num === undefined ? undefined : Number(num));
let width = toNumberFn(svgLengthToPx(documentElement.width) || undefined);
let height = toNumberFn(svgLengthToPx(documentElement.height) || undefined);
const alpha = toNumberFn(documentElement.getAttribute('opacity') || undefined);
const rootTransforms: Matrix[] = [];
const { viewBox } = documentElement;
if (viewBox && (!!viewBox.baseVal.width || !!viewBox.baseVal.height)) {
width = viewBox.baseVal.width;
height = viewBox.baseVal.height;
// Fake a translate transform for the viewbox.
rootTransforms.push(Matrix.translation(-viewBox.baseVal.x, -viewBox.baseVal.y));
}
const rootLayer = nodeToLayerFn(documentElement, rootTransforms);
return new VectorLayer({
id: _.uniqueId(),
name: makeFinalNodeIdFn(documentElement.getAttribute('id'), 'vector'),
children: rootLayer ? rootLayer.children : undefined,
width,
height,
alpha,
});
}