当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Matrix.flatten方法代码示例

本文整理汇总了TypeScript中app/scripts/common.Matrix.flatten方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Matrix.flatten方法的具体用法?TypeScript Matrix.flatten怎么用?TypeScript Matrix.flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app/scripts/common.Matrix的用法示例。


在下文中一共展示了Matrix.flatten方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: flattenGroupLayer

 /**
  * Merges the specified group layer into its children layers.
  * TODO: make it possible to merge groups that contain animation blocks?
  */
 flattenGroupLayer(layerId: string) {
   const vl = this.getVectorLayer();
   const layer = vl.findLayerById(layerId) as GroupLayer;
   if (!layer.children.length) {
     return;
   }
   const layerTransform = Matrix.flatten(LayerUtil.getCanvasTransformsForGroupLayer(layer));
   const layerChildren = layer.children.map((l: GroupLayer | PathLayer | ClipPathLayer): Layer => {
     if (l instanceof GroupLayer) {
       const flattenedTransform = Matrix.flatten([
         layerTransform,
         ...LayerUtil.getCanvasTransformsForGroupLayer(l),
       ]);
       const { sx, sy } = flattenedTransform.getScaling();
       const degrees = flattenedTransform.getRotation();
       const { tx, ty } = flattenedTransform.getTranslation();
       const newLayer = l.clone();
       newLayer.pivotX = 0;
       newLayer.pivotY = 0;
       newLayer.translateX = tx;
       newLayer.translateY = ty;
       newLayer.rotation = degrees;
       newLayer.scaleX = sx;
       newLayer.scaleY = sy;
       return newLayer;
     }
     const path = l.pathData;
     if (!path || !l.pathData.getPathString()) {
       return l;
     }
     const clonedLayer = l.clone();
     clonedLayer.pathData = path
       .mutate()
       .transform(layerTransform)
       .build();
     return clonedLayer;
   });
   const layerChildrenIds = new Set(layerChildren.map(l => l.id));
   const parent = LayerUtil.findParent(vl, layerId).clone();
   const children = [...parent.children];
   children.splice(_.findIndex(parent.children, l => l.id === layerId), 1, ...layerChildren);
   parent.children = children;
   const actions: Action[] = [
     new SetVectorLayer(LayerUtil.updateLayer(vl, parent)),
     ...this.buildCleanupLayerIdActions(layerId),
   ];
   const newAnimation = this.getAnimation().clone();
   // TODO: show a dialog if the user is about to unknowingly delete any blocks?
   newAnimation.blocks = newAnimation.blocks.filter(b => b.layerId !== layerId);
   // TODO: also attempt to merge children group animation blocks?
   newAnimation.blocks = newAnimation.blocks.map(b => {
     if (!(b instanceof PathAnimationBlock) || !layerChildrenIds.has(b.layerId)) {
       return b;
     }
     const block = b.clone();
     block.fromValue = block.fromValue
       .mutate()
       .transform(layerTransform)
       .build();
     block.toValue = block.toValue
       .mutate()
       .transform(layerTransform)
       .build();
     return block;
   });
   actions.push(new SetAnimation(newAnimation));
   this.store.dispatch(new BatchAction(...actions));
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:72,代码来源:layertimeline.service.ts

示例2: getNodeTransforms

  const nodeToLayerFn = (node: Element, transforms: ReadonlyArray<Matrix>): Layer => {
    if (
      !node ||
      node.nodeType === Node.TEXT_NODE ||
      node.nodeType === Node.COMMENT_NODE ||
      node instanceof SVGDefsElement ||
      node instanceof SVGUseElement
    ) {
      return undefined;
    }

    const nodeTransforms = getNodeTransforms(node as SVGGraphicsElement);
    transforms = [...transforms, ...nodeTransforms];
    const flattenedTransforms = Matrix.flatten(transforms);

    // Get the referenced clip-path ID, if one exists.
    const refClipPathId = getReferencedClipPathId(node);

    const maybeWrapClipPathInGroupFn = (layer: Layer) => {
      if (!refClipPathId) {
        return layer;
      }
      const paths = (clipPathMap[refClipPathId] || []).map(p => {
        return new Path(
          p
            .mutate()
            .transform(flattenedTransforms)
            .build()
            .getPathString(),
        );
      });
      if (!paths.length) {
        // If the clipPath has no children, then clip the entire layer.
        paths.push(new Path('M 0 0 Z'));
      }
      const groupChildren: Layer[] = paths.map(p => {
        return new ClipPathLayer({
          name: makeFinalNodeIdFn(refClipPathId, 'mask'),
          pathData: p,
          children: [],
        });
      });
      groupChildren.push(layer);
      return new GroupLayer({
        name: makeFinalNodeIdFn('wrapper', 'group'),
        children: groupChildren,
      });
    };

    if (node instanceof SVGPathElement && node.getAttribute('d')) {
      const path = node.getAttribute('d');
      const attrMap: Dictionary<any> = {};
      const simpleAttrFn = (nodeAttr: string, contextAttr: string) => {
        if (node.hasAttribute(nodeAttr)) {
          attrMap[contextAttr] = node.getAttribute(nodeAttr);
        }
      };

      simpleAttrFn('stroke', 'strokeColor');
      simpleAttrFn('stroke-width', 'strokeWidth');
      simpleAttrFn('stroke-linecap', 'strokeLinecap');
      simpleAttrFn('stroke-linejoin', 'strokeLinejoin');
      simpleAttrFn('stroke-miterlimit', 'strokeMiterLimit');
      simpleAttrFn('stroke-opacity', 'strokeAlpha');
      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());
      }
//.........这里部分代码省略.........
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:101,代码来源:SvgLoader.ts


注:本文中的app/scripts/common.Matrix.flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。