本帖最后由 dexteryao 于 2016-9-29 10:49 编辑
垂直的对齐需要根据字体大小调整,比较麻烦,如果要改最好根据您的设置直接hard code吧。
- RightStartCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- if (!ctx) {
- return;
- }
- GcSpread.Sheets.TextCellType.prototype.paint.call(this, ctx, "", x, y, w, h, style, options);
- ctx.font = style.font;
- var star = "* ";
- var textWidth = ctx.measureText(value).width;
- var starWidth = ctx.measureText(star).width;
-
- var hAlign = style.hAlign
- ctx.save();
- // draw inside the cell's boundary
- ctx.rect(x, y, w, h);
- ctx.clip();
- ctx.textAlign="start";
- ctx.textBaseline="middle";
- if(hAlign === 1){
- // center
- ctx.fillText(value, x + w / 2 - textWidth / 2, y + h / 2);
- ctx.fillStyle = "red";
- ctx.fillText(star, x + w / 2 + textWidth / 2, y + h / 2);
- }
- else if(hAlign === 2){
- // right
- ctx.fillText(value, x + w - textWidth - starWidth, y + h / 2);
- ctx.fillStyle = "red";
- ctx.fillText(star, x + w - starWidth, y + h / 2);
- }
- else{
- ctx.fillText(text, x, y + h / 2);
- ctx.fillText(star, x + textWidth, y + h / 2);
- }
- ctx.restore();
- };
- };
复制代码 |