// 底稿取值类型
var ShowDgFetch = (function () {
function ShowDgFetch() {
this.typeName = 'ShowDgFetch';
this._cellTagStartCache = undefined;
this._textWidth = undefined;
}
ShowDgFetch.prototype = new GC.Spread.Sheets.CellTypes.Text();
ShowDgFetch.prototype.paintContent = function (ctx, value, x, y, w, h, style, context) {
var tag = context.sheet.getTag(context.row, context.col);
if (tag == '' || tag == null || tag === undefined) {
this._cellTagStartCache = undefined;
this._textWidth = undefined;
GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, value, x, y, w, h, style, context);
return;
}
this._cellTagStartCache = [], this._textWidth = 0;
var startTextWidth = 0, endTextWidth = 0;
var sheet = context.sheet, zoomFactor = sheet.zoom();
var foreColor = style.foreColor, textDecoration = style.textDecoration;
//为了实现简单,单元格垂直居中,如果有其他需求,绘制文字位置重新计算
style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
for (var i = 0; i < tag.cellTagStart.length; i++) {
var node = tag.cellTagStart[i;
if (node.type === 'link') {
style.foreColor = 'blue';
style.textDecoration = GC.Spread.Sheets.TextDecorationType.underline;
var linkText = node.linkText;
GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, linkText, x + startTextWidth + 2, y, w - startTextWidth, h, style, context);
var textWidth = GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, linkText, linkText, style, zoomFactor, context);
this._cellTagStartCache[i] = {
startX: x + startTextWidth,
textWidth: textWidth + 3,
dgFileId: node.dgFileId,
dgFileInputVal: node.dgFileInputVal,
dgFileInputText: node.dgFileInputText,
dgFileSelectVal: node.dgFileSelectVal,
dgSheetSelectVal: node.dgSheetSelectVal,
dgSheetName: node.dgSheetName,
dgRange: node.dgRange,
linkText: node.linkText,
type: node.type
};
startTextWidth += (textWidth + 3);
}
}
this._textWidth += startTextWidth;
// Set Font to default
style.foreColor = foreColor;
style.textDecoration = textDecoration;
//Paint Value
// style.font = 'bold ' + style.font;
style.hAlign = GC.Spread.Sheets.HorizontalAlign.right;
style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
GC.Spread.Sheets.CellTypes.Text.prototype.paintContent.call(this, ctx, value, x, y, w - endTextWidth - 3, h, style, context)
};
ShowDgFetch.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
var info = {
x: x,
y: y,
row: context.row,
col: context.col,
cellRect: cellRect,
sheetArea: context.sheetArea,
isReservedLocation: false,
reservedLocation: -1
};
for (var i = 0; i < this._cellTagStartCache.length; i++) {
var item = this._cellTagStartCache[i;
if (item) {
var startX = item.startX;
if (x - startX > 0 && x < startX + item.textWidth) {
info.isReservedLocation = true;
info.reservedLocation = i;
break;
}
}
}
return info;
};
ShowDgFetch.prototype.processMouseUp = function (hitInfo) {
return false;
};
ShowDgFetch.prototype.processMouseMove = function (hitInfo) {
return false;
};
ShowDgFetch.prototype.processMouseLeave = function (hitInfo) {
};
ShowDgFetch.prototype.getAutoFitWidth = function (value, text, cellStyle, zoomFactor, context) {
if (this._textWidth) {
// cellStyle.font = 'bold ' + cellStyle.font;
return 5 + this._textWidth + GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, value, text, cellStyle, zoomFactor, context);
} else {
return GC.Spread.Sheets.CellTypes.Text.prototype.getAutoFitWidth.call(this, value, text, cellStyle, zoomFactor, context)
}
};
return ShowDgFetch;
})();
designer.ShowDgFetch = ShowDgFetch;
|