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

关于leafer-x-ruler默认单位px转mm的需求 #295

Open
wzjiscode opened this issue Dec 20, 2024 · 3 comments
Open

关于leafer-x-ruler默认单位px转mm的需求 #295

wzjiscode opened this issue Dec 20, 2024 · 3 comments

Comments

@wzjiscode
Copy link

wzjiscode commented Dec 20, 2024

移动端px转mm需求:

  1. 设置屏幕的宽度(假设)是30mm,高度(假设)是100mm
  2. 根据设置的宽度铺满全屏,这时1mm就需要重新计算占比多少px
  3. 高度根据宽度的占比计算得到的就是准确的宽高比
    个人实现:曾自己实现一版只是改了源码部分draw方法,没有考虑缩放等因素(对于源码理解不透彻导致),导致滚动条没有随画布滚动而滚动。
    期望:在现有卡尺效果的基础上,将px转mm即可
@leaferjs
Copy link
Owner

已经转发到6个群里了~

@xhlsrj
Copy link

xhlsrj commented Dec 20, 2024

draw函数中gap控制单位长度,是像素值,textValue控制显示单位的文本,调整这两个变量即可。
举例:以 10mm 为单位长度渲染标尺,假定 1mm = 3.78px。gap = (this.getGap(zoom) / 100) * 3.78 * 10textValue = ((startValue + pos) / 3.78).toFixed(0)即可。
补充说明:getGap函数当 zoom = 1 时返回值是 100
补充提示:1. 左上角单位;2. 数值计算精度。

@wzjiscode
Copy link
Author

draw函数中gap控制单位长度,是像素值,textValue控制显示单位的文本,调整这两个变量即可。 举例:以 10mm 为单位长度渲染标尺,假定 1mm = 3.78px。gap = (this.getGap(zoom) / 100) * 3.78 * 10textValue = ((startValue + pos) / 3.78).toFixed(0)即可。 补充说明:getGap函数当 zoom = 1 时返回值是 100。 补充提示:1. 左上角单位;2. 数值计算精度。

大佬好使,顶礼膜拜!!!

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