How to use the paper.Size function in paper

To help you get started, we’ve selected a few paper examples, based on popular ways it is used in public projects.

github techninja / cncserver / src / components / core / drawing / cncserver.drawing.base.js View on Github external
cncserver.binder.bindTo('controller.setup', base.id, () => {
    const { settings: { bot } } = cncserver;
    console.log(bot);
    // Setup the project with the max cavas size in mm.
    base.size = new Size(bot.maxAreaMM.width, bot.maxAreaMM.height);

    // Setup the actual printable work space as a rectangle.
    base.workspace = new Rectangle({
      from: [bot.workAreaMM.left, bot.workAreaMM.top],
      to: [bot.workAreaMM.right, bot.workAreaMM.bottom],
    });

    base.project = new Project(base.size);

    // Setup layers: temp, working
    // Whatever the last layer added was, will be default.
    base.layers = {
      import: new Layer(),
      temp: new Layer(),
      preview: new Layer(),
    };
github fponticelli / tempo / demo / paper / src / paint / reducer.ts View on Github external
const fitSize = (image: HTMLImageElement, size: Size) => {
  const iw = image.width
  const ih = image.height
  const ir = iw / ih
  const cw = size.width!
  const ch = size.height!
  const cr = cw / ch

  if (ir < cr) {
    const ratio = cw / iw
    return new Size(iw * ratio, ih * ratio)
  } else {
    const ratio = ch / ih
    return new Size(iw * ratio, ih * ratio)
  }
}
github googlefonts / korean / app / components / FontOutlineViewer.js View on Github external
height = containerHeight;

      
      } else {

        width = screenWidth - 24 * 2;
        height = containerHeight;

      }
      
      this.view.viewSize = new paper.Size(width, height);

    } else {

      leftWidthScale = scaleLinear().domain([480, 1440]).clamp(true).range([65, 230]);
      this.view.viewSize = new paper.Size( (screenWidth - 24 * 2) - leftWidthScale(screenWidth), containerHeight );
    }
    
  }
github alexjlockwood / ShapeShifter / src / app / pages / editor / scripts / paper / item / PaperLayer.ts View on Github external
constructor(private readonly ps: PaperService) {
    super();
    this.canvasColorRect = new paper.Path.Rectangle(new paper.Point(0, 0), new paper.Size(0, 0));
    this.canvasColorRect.guide = true;
    this.updateChildren();
  }
github react-paper / react-paper-bindings / src / react-paper-bindings.js View on Github external
componentDidUpdate(prevProps, prevState) {
    const {
      children, height, width,
      cx, cy, dx, dy, x, y, zoom,
    } = this.props

    PaperRenderer.updateContainer(
      children,
      this._mountNode,
      this,
    )

    const { view } = this._paper

    if (width !== prevProps.width || height !== prevProps.height) {
      view.viewSize = new Size(width, height)
    }

    if (zoom !== prevProps.zoom) {
      view.scale(zoom / prevProps.zoom, view.viewToProject(cx, cy))
    } else if (x !== prevProps.x || y !== prevProps.y) {
      view.translate(dx, dy)
    }
  }
github mydraft-cc / ui / src / core / utils / paper-helper.ts View on Github external
import * as paper from 'paper';

import {
    Color,
    Rect2,
    Vec2
} from '@app/core';

export interface PaperTextGroup { textItem: paper.TextItem; groupItem: paper.Group; }

export module PaperHelper {
    export const COLOR_BLACK = new paper.Color(0, 0, 0, 1);
    export const COLOR_WHITE = new paper.Color(1, 1, 1, 1);
    export const ZERO_POINT = new paper.Point(0, 0);
    export const ZERO_SIZE = new paper.Size(0, 0);
    export const ZERO_RECTANGLE = new paper.Rectangle(0, 0, 0, 0);
    export const IDENTITY_MATRIX = new paper.Matrix(1, 0, 0, 1, 0, 0);

    export function createSinglelineText(rectangle: paper.Rectangle, text: string, fontSize?: number, alignment?: string): PaperTextGroup {
        fontSize = fontSize || 10;

        alignment = alignment || 'center';

        const clip = new paper.Path.Rectangle(rectangle);

        let y = rectangle.center.y + fontSize * 1.2 * 0.25;
        let x = rectangle.center.x;

        if (alignment === 'left') {
            x = rectangle.left;
        } else if (alignment === 'right') {
github mydraft-cc / ui / src / core / utils / paper-helper.ts View on Github external
export function vec2Size(vec: Vec2): paper.Size {
        return new paper.Size(vec.x, vec.y);
    }
github alexjlockwood / ShapeShifter / src / app / modules / editor / scripts / paper / item / PaperLayer.ts View on Github external
private updateCanvasColorShape() {
    this.canvasColorRect = new paper.Path.Rectangle(
      new paper.Point(0, 0),
      new paper.Size(this.vectorLayer.width, this.vectorLayer.height),
    );
    this.canvasColorRect.guide = true;
    this.canvasColorRect.fillColor = parseAndroidColor(this.vectorLayer.canvasColor) || 'white';
    this.updateChildren();
  }