更新文本背景自适应
This commit is contained in:
parent
794b1f0617
commit
5a78e68a26
52
lib/pen.js
52
lib/pen.js
@ -253,11 +253,61 @@ export default class Painter {
|
||||
this.ctx.restore();
|
||||
this._doBorder(view, width, height);
|
||||
}
|
||||
|
||||
_fillAbsTextBackground(view) {
|
||||
this.ctx.save();
|
||||
let { background , padding } = view.css;
|
||||
const {
|
||||
width,
|
||||
height
|
||||
} = this._preProcess(view);
|
||||
this.ctx.restore();
|
||||
let pd = [0, 0, 0, 0];
|
||||
if(padding) {
|
||||
let pdg = padding.split(' ');
|
||||
if(pdg.length == 1) {
|
||||
let x = parseInt(pdg[0]);
|
||||
pd = [x, x, x, x];
|
||||
}
|
||||
if(pdg.length == 2) {
|
||||
let x = parseInt(pdg[0]);
|
||||
let y = parseInt(pdg[1]);
|
||||
pd = [x, y, x, y];
|
||||
}
|
||||
if(pdg.length == 3) {
|
||||
let x = parseInt(pdg[0]);
|
||||
let y = parseInt(pdg[1]);
|
||||
let z = parseInt(pdg[2]);
|
||||
pd = [x, y, z, y];
|
||||
}
|
||||
if(pdg.length == 4) {
|
||||
let x = parseInt(pdg[0]);
|
||||
let y = parseInt(pdg[1]);
|
||||
let z = parseInt(pdg[2]);
|
||||
let a = parseInt(pdg[3]);
|
||||
pd = [x, y, z, a];
|
||||
}
|
||||
}
|
||||
let gview = {
|
||||
type: 'rect',
|
||||
css: {
|
||||
top: (parseInt(view.css.top) - pd[0]) + 'rpx',
|
||||
left: (parseInt(view.css.left) - pd[3]) + 'rpx',
|
||||
width: ((width + 'px').toRpx() + pd[1] + pd[3]) + 'rpx',
|
||||
height: ((height + 'px').toRpx() + pd[0] + pd[2]) + 'rpx',
|
||||
color: background,
|
||||
borderRadius: view.css.borderRadius || '0rpx'
|
||||
}
|
||||
}
|
||||
this._drawAbsRect(gview);
|
||||
}
|
||||
_fillAbsText(view) {
|
||||
if (!view.text) {
|
||||
return;
|
||||
}
|
||||
if(view.css.background) {
|
||||
// 生成背景
|
||||
this._fillAbsTextBackground(view);
|
||||
}
|
||||
this.ctx.save();
|
||||
const {
|
||||
width,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user