Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
mp-painter
Advanced tools
npm install mp-painter --save
<template>
<canvas canvas-id="canvas"></canvas>
</template>
import Painter from "mp-painter";
// onReady 中
let painter = new Painter(uni.createCanvasContext("canvas"));
await painter.draw({
type: "text",
color: "#fcc",
fontSize: 60, // = 60rpx
content: "Hello World" //绘制的文本
});
更多示例可参考 example 文件夹
new Painter(
ctx: CanvasContext,
{ platform?: "mp-weixin" | "mp-alipay" | "mp-baidu" } = {}
): Painter
绘制时使用的方法
draw(绘制对象): Promise<{ width: number, height: number }>
帮助函数,用于手动测量文本
measureText(text: string, fontSize: number): number
任意一类绘制对象都支持以下属性
字段名 | 类型 | 默认值 |
---|---|---|
type | "text" / "text-block" / "image" / "line" / "rect" / "container" | - |
position | "static" / "absolute" | static |
top | number | 0 |
left | number | 0 |
type
表示要绘制的元素的类型position
定位模式top
/left
在 'absolute' 定位模式中表示距离父级 container 或 canvas 顶/左边的距离,
在 'static' 定位模式中,表示距离前一个 'static' 元素最下/右边的距离,有关元素排列方向,请参考 containertext 用于绘制单行文本
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
content | string | "" | 文本内容 |
color | string | "#000" | 文本颜色 |
fontSize | number | 30 | 字号 |
fontWeight | "normal" / "bold" | "normal" | 字重 |
fontFamily | string | "serial" | 字体 |
baseline | "top" / "middle" / "bottom" / "normal" | "top" | 基线 |
align | "left"/ "right"/ "center" | "left" | 文本对齐 |
width | number | null | 元素的宽度, 水平排布时影响后一个元素的位置,为 null 时根据文字实际占用的宽度计算 |
text-block 用于绘制文本框
text-block 除了支持 text 所有的选项字段外还支持以下字段
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
lineHeight | number | 40 | 文本行高 |
lineClamp | number | 0 | 文本显示的最大行数,0表示不限制 |
width | number | 100 | 文本块换行前的最大宽度 |
rect 用于绘制矩形,暂不支持投影
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
width | number | 100 | 矩形的宽 |
height | number | 100 | 矩形的高 |
background | string | #000 | 填充的颜色 |
borderRadius | number/[number,number,number,number] | 0 | 圆角 |
line 用于绘制实线及虚线
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
dx | number | 0 | 直线在 x 方向上的跨度 |
dy | number | 0 | 直线在 y 方向上的跨度 |
color | string | - | 直线的颜色 |
lineWidth | number | 1 | 直线的宽度 |
dashPattern | number[] | [1,0] | 虚线样式 |
image 用于绘制图片
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
src | string | - | 图片的地址,支持外链地址/本地地址/临时地址 |
width | number | - | 图片的宽度 |
height | number | - | 图片的高度 |
objectFit | "fill"/"contain" | "fill" | 与 css 的 objct-fit 属性含义相同 |
container 用于容纳多个绘图元素,并提供 absolute 定位基准
字段名 | 类型 | 默认值 | 描述 |
---|---|---|---|
direction | "vertical" / "horizontal" | "vertical" | 指定内部 static 元素的排列方向 |
width | number / "auto" | "auto" | 容器的宽度,"auto" 表示根据内部元素尺寸决定 |
height | number / "auto" | "auto" | 容器的宽高度,"auto" 表示根据内部元素尺寸决定 |
children | 绘制对象[] | [] | 容器内部的元素 |
FAQs
A declarative canvas lib using with mini-program, espacially with uniapp.
The npm package mp-painter receives a total of 6 weekly downloads. As such, mp-painter popularity was classified as not popular.
We found that mp-painter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.