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

reset size by this.isVertical() ,it does not compatible width canvas that width not equal height #220

Closed
yangfan0095 opened this issue Jan 22, 2018 · 2 comments

Comments

@yangfan0095
Copy link

yangfan0095 commented Jan 22, 2018

Summary : when the react render ,the getDimensions() will be call , and you will reset the size according to the function this.isVertical(). and the key is the function this.isVertical() that
you judge if it is vertical by this.props.rotate % 180 !== 0 。 if you judge by this , it will not compatible width canvas that width not equal height. just like my project .

if the canvas width not equal height , when rotate will be canvas will be reset 。 just like the picture

image

when rotate , it will be deform ,it just seem not support rectangle

image

i saw your code .
when the react render ,the getDimensions() will be call , and you will reset the size according to the this.isVertical(). and the key is the function this.isVertical()
you judge if it is vertical by this.props.rotate % 180 !== 0 。 if you judge by this , it will not compatible width canvas that width not equal height. just like my project .

 render () {
    const dimensions = this.getDimensions()
...
  getDimensions () {
    const { width, height, rotate, border } = this.props

    const canvas = {}

    const [borderX, borderY] = this.getBorders(border)

    const canvasWidth = width
    const canvasHeight = height

//  here is the judge way
    if (this.isVertical()) {
      canvas.width = canvasHeight
      canvas.height = canvasWidth
    } else {
      canvas.width = canvasWidth
      canvas.height = canvasHeight
    }

    canvas.width += borderX * 2
    canvas.height += borderY * 2

    return {
      canvas,
      rotate,
      width,
      height,
      border
    }
  }

and the isVertical

isVertical () {
    return this.props.rotate % 180 !== 0
  }

such as my project :

image

@yangfan0095
Copy link
Author

i fix my problem by change your original code . and I think maybe you can provide a API to controller that 🙂

isVertical () {
   -  return this.props.rotate % 180 !== 0;
   + return false;
  }

@yangfan0095 yangfan0095 changed the title reset size according to this.isVertical() ,it will not compatible width canvas that width not equal height reset size according to this.isVertical() ,it does not compatible width canvas that width not equal height Jan 22, 2018
@yangfan0095 yangfan0095 changed the title reset size according to this.isVertical() ,it does not compatible width canvas that width not equal height reset size by this.isVertical() ,it does not compatible width canvas that width not equal height Jan 22, 2018
@GeorgiosP
Copy link

Is this a PR'd fix or should I also modify it?

@mosch mosch closed this as completed Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants