lufy's legend
标题:
LTextField 添加描边的修改
[打印本页]
作者:
陈前帆
时间:
2013-12-2 11:10
标题:
LTextField 添加描边的修改
构造函数中添加
s.attachStroke = false;//填充并且描边。
s.attachStrokeColor = "#ffffff";
重写
show:function (){
var s = this,c = LGlobal.canvas;
if(!s.visible)return;
c.save();
c.font = s.weight + " " + s.size+"pt "+s.font;
c.textAlign = s.textAlign;
c.textBaseline = s.textBaseline;
c.lineWidth = s.lineWidth;
if(s.filters){
s.setShadow();
}
if(s.alpha < 1){
c.globalAlpha = s.alpha;
}
if(s.mask != null && s.mask.show){
s.mask.show();
c.clip();
}
if(s.blendMode){
c.globalCompositeOperation = s.blendMode;
}
s._transformScale();
s._transformRotate();
if(s.x != 0 || s.y != 0)c.transform(1,0,0,1,s.x,s.y);
if(s.texttype == LTextFieldType.INPUT){
if(s.x != 0 || s.y != 0){
s.inputBackLayer.show();
}
var rc = s.getRootCoordinate();
if(LGlobal.inputBox.name == "input"+s.objectIndex){
LGlobal.inputBox.style.marginTop = (rc.y) + "px";
LGlobal.inputBox.style.marginLeft = (rc.x) + "px";
}
}
var lbl = s.text;
if(s.displayAsPassword){
lbl = '';
for(var i=0,l=s.text.length;i<l;i++)lbl+='*';
}
var d;
var ds; // 专门描绘附加描边
if(s.stroke){
c.strokeStyle = s.color;
d = c.strokeText;
}else{
//附加描边
if(s.attachStroke){
ds = c.strokeText;
}
c.fillStyle = s.color;
d = c.fillText;
}
if(s.wordWrap){
var i,l,j=0,k=0,m=0;
for(i=0,l=s.text.length;i<l;i++){
j = c.measureText(s.text.substr(k,i-k)).width;
if(j > s.width){
j = 0;
k = i;
m++;
}
d.apply(c,[lbl.substr(i,1),j,m*s.wordHeight,c.measureText(lbl).width]);
if(ds instanceof Function){
c.strokeStyle = s.attachStrokeColor; //修改处
ds.apply(c,[lbl.substr(i,1),j,m*s.wordHeight,c.measureText(lbl).width]);
}
}
s.height = m*s.wordHeight;
}else{
d.apply(c,[lbl,0,0,c.measureText(lbl).width]);
if(ds instanceof Function){
c.strokeStyle = s.attachStrokeColor; //修改处
ds.apply(c,[lbl,0,0,c.measureText(lbl).width]);
}
}
if(s.wind_flag){
s.windRun();
}
c.restore();
},
作者:
陈前帆
时间:
2013-12-2 11:11
经我测试实际效果一般,希望有更好的解决描边的方法。
作者:
lufy
时间:
2013-12-3 00:52
陈前帆 发表于 2013-12-2 11:11
经我测试实际效果一般,希望有更好的解决描边的方法。
引擎中有光晕效果,就是影子了,可以在文字四周加上光晕,类似于描边效果。
描边相当于绘制两边文字,效率不可能兼得了。
欢迎光临 lufy's legend (http://lufylegend.com/forum/)
Powered by Discuz! X2.5