Skip to content

Commit

Permalink
feat: $geom的内容判定更新 #251
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Nov 2, 2022
1 parent ee593ad commit c6871b9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 99 deletions.
102 changes: 53 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22252,26 +22252,38 @@
value: function calContent(currentStyle, computedStyle) {
var res = _get(_getPrototypeOf(Geom.prototype), "calContent", this).call(this, currentStyle, computedStyle);

if (!res) {
var fill = computedStyle[FILL$1],
stroke = computedStyle[STROKE],
strokeWidth = computedStyle[STROKE_WIDTH$6];
this.__hasXomContent = res;
var fill = computedStyle[FILL$1],
stroke = computedStyle[STROKE],
strokeWidth = computedStyle[STROKE_WIDTH$6];
var empty = true;

for (var i = 0, len = fill.length; i < len; i++) {
var item = fill[i];
for (var i = 0, len = fill.length; i < len; i++) {
var item = fill[i];

if (item.k || item[3] > 0) {
return true;
}
if (item.k || item[3] > 0) {
empty = false;
break;
}
}

for (var _i = 0, _len = stroke.length; _i < _len; _i++) {
var _item = stroke[_i];
for (var _i = 0, _len = stroke.length; _i < _len; _i++) {
var _item = stroke[_i];

if ((_item.k || _item[3] > 0) && strokeWidth[_i] > 0) {
return true;
}
if ((_item.k || _item[3] > 0) && strokeWidth[_i] > 0) {
empty = false;
break;
}
} // 矢量图形默认有内容


if (!empty) {
return true;
} // 没有fill和stroke则认为矢量图形为空


if (!res && empty) {
return false;
}

return res;
Expand Down Expand Up @@ -36047,42 +36059,9 @@
_mixBlendMode = __computedStyle[MIX_BLEND_MODE$1],
_perspective2 = __computedStyle[PERSPECTIVE];

var _isMbm = _mixBlendMode !== 'normal'; // let __domParent = node.__domParent;


var _isPpt = total && (_perspective2 || isPerspectiveMatrix(node.__matrix)); // 有perspective的父或者自身transform包含的都是局部根节点
// let isPptParent = __domParent && !isE(__domParent.__perspectiveMatrix) && total;
// let isPptSelf = isPerspectiveMatrix(node.__matrix) && total;
// let isPpt = isPptParent || isPptSelf;
// ppt几种情况非常复杂,需分开考虑
// let pptEnv, isPpt;
// // ppt在自身身上特殊处理,自身即是局部根节点也是直接子节点,如果父还是ppt可以忽略,因为功能正好重合
// if(isPptSelf) {
// isPpt = true;
// pptEnv = {
// flat: isFlat,
// node,
// };
// }
// // ppt节点需局部根节点位图缓存,防止重合,同时透视子孙要切割平面
// else if(perspective && total) {
// isPpt = true;
// }
// // 父是ppt,直接子节点强制参与透视,当父是flat时,直接子节点子孙都是透视投影,需切割面后投影
// else if(isPptParent && parentFlat) {
// pptEnv = {
// flat: isFlat,
// node: parentPptNode,
// };
// }
// // transformStyle变化的非ppt直接子节点,根据父是否flat决定是否拆面,一定投影
// else if(parentPptNode && total && parentFlat !== isFlat) {
// pptEnv = {
// flat: isFlat,
// node: parentPptNode,
// };
// }
var _isMbm = _mixBlendMode !== 'normal';

var _isPpt = total && (_perspective2 || isPerspectiveMatrix(node.__matrix));

var isOverflow = overflow === 'hidden' && total;
var isFilter = _filter && _filter.length;
Expand Down Expand Up @@ -41636,6 +41615,31 @@
}

_createClass(Polyline, [{
key: "calContent",
value: function calContent(currentStyle, computedStyle) {
var res = _get(_getPrototypeOf(Polyline.prototype), "calContent", this).call(this, currentStyle, computedStyle); // 查看是否有顶点


if (res && !this.__hasXomContent) {
var points = this.__cacheProps.points,
isMulti = this.isMulti;

if (isMulti) {
for (var i = 0, len = points.length; i < len; i++) {
if (points.length) {
return true;
}
}

return false;
} else {
return !!points.length;
}
}

return res;
}
}, {
key: "__getPoints",
value: function __getPoints(originX, originY, width, height, points, isControl) {
return points.map(function (item) {
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

42 changes: 26 additions & 16 deletions src/node/geom/Geom.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,35 @@ class Geom extends Xom {

calContent(currentStyle, computedStyle) {
let res = super.calContent(currentStyle, computedStyle);
if(!res) {
let {
[FILL]: fill,
[STROKE]: stroke,
[STROKE_WIDTH]: strokeWidth,
} = computedStyle;
for(let i = 0, len = fill.length; i < len; i++) {
let item = fill[i];
if(item.k || item[3] > 0) {
return true;
}
this.__hasXomContent = res;
let {
[FILL]: fill,
[STROKE]: stroke,
[STROKE_WIDTH]: strokeWidth,
} = computedStyle;
let empty = true;
for(let i = 0, len = fill.length; i < len; i++) {
let item = fill[i];
if(item.k || item[3] > 0) {
empty = false;
break;
}
for(let i = 0, len = stroke.length; i < len; i++) {
let item = stroke[i];
if((item.k || item[3] > 0) && strokeWidth[i] > 0) {
return true;
}
}
for(let i = 0, len = stroke.length; i < len; i++) {
let item = stroke[i];
if((item.k || item[3] > 0) && strokeWidth[i] > 0) {
empty = false;
break;
}
}
// 矢量图形默认有内容
if(!empty) {
return true;
}
// 没有fill和stroke则认为矢量图形为空
if(!res && empty) {
return false;
}
return res;
}

Expand Down
20 changes: 20 additions & 0 deletions src/node/geom/Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,26 @@ class Polyline extends Geom {
}
}

calContent(currentStyle, computedStyle) {
let res = super.calContent(currentStyle, computedStyle);
// 查看是否有顶点
if(res && !this.__hasXomContent) {
let { __cacheProps: { points }, isMulti } = this;
if(isMulti) {
for(let i = 0, len = points.length; i < len; i++) {
if(points.length) {
return true;
}
}
return false;
}
else {
return !!points.length;
}
}
return res;
}

__getPoints(originX, originY, width, height, points, isControl) {
return points.map(item => {
if(!Array.isArray(item)) {
Expand Down
33 changes: 0 additions & 33 deletions src/refresh/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -2380,40 +2380,7 @@ function renderWebgl(renderMode, gl, root, isFirst, rlv) {
[PERSPECTIVE]: perspective,
} = __computedStyle;
let isMbm = mixBlendMode !== 'normal';
// let __domParent = node.__domParent;
let isPpt = total && (perspective || isPerspectiveMatrix(node.__matrix));
// 有perspective的父或者自身transform包含的都是局部根节点
// let isPptParent = __domParent && !isE(__domParent.__perspectiveMatrix) && total;
// let isPptSelf = isPerspectiveMatrix(node.__matrix) && total;
// let isPpt = isPptParent || isPptSelf;
// ppt几种情况非常复杂,需分开考虑
// let pptEnv, isPpt;
// // ppt在自身身上特殊处理,自身即是局部根节点也是直接子节点,如果父还是ppt可以忽略,因为功能正好重合
// if(isPptSelf) {
// isPpt = true;
// pptEnv = {
// flat: isFlat,
// node,
// };
// }
// // ppt节点需局部根节点位图缓存,防止重合,同时透视子孙要切割平面
// else if(perspective && total) {
// isPpt = true;
// }
// // 父是ppt,直接子节点强制参与透视,当父是flat时,直接子节点子孙都是透视投影,需切割面后投影
// else if(isPptParent && parentFlat) {
// pptEnv = {
// flat: isFlat,
// node: parentPptNode,
// };
// }
// // transformStyle变化的非ppt直接子节点,根据父是否flat决定是否拆面,一定投影
// else if(parentPptNode && total && parentFlat !== isFlat) {
// pptEnv = {
// flat: isFlat,
// node: parentPptNode,
// };
// }
let isOverflow = overflow === 'hidden' && total;
let isFilter = filter && filter.length;
if(isMbm) {
Expand Down
4 changes: 4 additions & 0 deletions test/group4/webgl-custom/script.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ function loadShader(gl, type, source) {
}

class $custom extends karas.Geom {
calContent(cr, cp) {
let res = super.calContent(cr, cp);
return res || true;
}
render(renderMode, ctx, dx, dy) {
let res = super.render(renderMode, ctx, dx, dy);
if(renderMode === karas.mode.WEBGL) {
Expand Down

0 comments on commit c6871b9

Please sign in to comment.