Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat: add display underline depending on type (#5787)

Roman Sergeev034a9236f2fe
diff --git a/mockdata/src/docs/default-document.data-simple.ts b/mockdata/src/docs/default-document.data-simple.ts
index cf84bff892..90f7ad820f 100644
--- a/mockdata/src/docs/default-document.data-simple.ts
+++ b/mockdata/src/docs/default-document.data-simple.ts
@@ -54,10 +54,26 @@ const exampleTables = [
const title = 'Examples of Accessible Data Tables\r';
const description = 'Basic Data Table with Column Headings\r';
+
+const dotted = 'dotted\r';
+const dotted_heavy = 'dotted_heavy\r';
+const dash = 'dash\r';
+const dashed_heavy = 'dashed_heavy\r';
+const dash_long = 'dash_long\r';
+const dash_long_heavy = 'dash_long_heavy\r';
+const dot_dash = 'dot_dash\r';
+const dash_dot_heavy = 'dash_dot_heavy\r';
+const dot_dot_dash = 'dot_dot_dash\r';
+const dash_dot_dot_heavy = 'dash_dot_dot_heavy\r';
+const thick = 'thick\r';
+const wave = 'wave\r';
+
+const underline = `${dotted}${dotted_heavy}${dash}${dashed_heavy}${dash_long}${dash_long_heavy}${dot_dash}${dash_dot_heavy}${dot_dot_dash}${dash_dot_dot_heavy}${thick}${wave}`;
+
const summary = 'These example tables contain captions and summaries. When you copy any of these tables into your page you must edit the caption and summary. The caption can be edited in the Design view but the summary text must be edited in Code view. Click inside the table, then select the table tag on the tag selector, then switch to Code view and edit the text in the summary attribute.\r';
const tableStream = createTableDataStream(exampleTables);
-const dataStream = `${title}${description}${tableStream}${summary}\n`;
+const dataStream = `${title}${description}${underline}${tableStream}${summary}\n`;
const startIndex = dataStream.indexOf(TABLE_START);
const endIndex = tableStream.length + startIndex;
@@ -126,6 +142,234 @@ function createTextRuns() {
offset += description.length;
+ textRuns.push({
+ st: offset,
+ ed: offset + dotted.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 8,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dotted.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dotted_heavy.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 9,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dotted_heavy.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dash.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 0,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dash.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dashed_heavy.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 3,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dashed_heavy.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dash_long.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 4,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dash_long.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dash_long_heavy.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 5,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dash_long_heavy.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dot_dash.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 6,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dot_dash.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dash_dot_heavy.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 2,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dash_dot_heavy.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dot_dot_dash.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 7,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dot_dot_dash.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + dash_dot_dot_heavy.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 1,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += dash_dot_dot_heavy.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + thick.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 13,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += thick.length;
+
+ textRuns.push({
+ st: offset,
+ ed: offset + wave.length,
+ ts: {
+ fs: 12,
+ ff: 'Helvetica Neue',
+ cl: {
+ rgb: '#54585a',
+ },
+ ul: {
+ s: 1,
+ t: 14,
+ },
+ bl: BooleanNumber.FALSE,
+ },
+ });
+
+ offset += wave.length;
+
textRuns.push({
st: offset,
ed: offset + tableStream.length,
diff --git a/mockdata/src/sheets/demo/default-workbook-data-demo.ts b/mockdata/src/sheets/demo/default-workbook-data-demo.ts
index 7771574db1..ea7f8a52a0 100644
--- a/mockdata/src/sheets/demo/default-workbook-data-demo.ts
+++ b/mockdata/src/sheets/demo/default-workbook-data-demo.ts
@@ -14508,6 +14508,149 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
s: 'pwABhz',
},
},
+ 28: {
+ 12: {
+ v: 'DASH DASH DASH',
+ s: {
+ ul: {
+ s: 1,
+ t: 0,
+ },
+ },
+ },
+ },
+ 30: {
+ 12: {
+ v: 'DASH DOT DOT HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 1,
+ },
+ },
+ },
+ },
+ 32: {
+ 12: {
+ v: 'DASH DOT HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 2,
+ },
+ },
+ },
+ },
+ 34: {
+ 12: {
+ v: 'DASHED HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 3,
+ },
+ },
+ },
+ },
+ 36: {
+ 12: {
+ v: 'DASH LONG',
+ s: {
+ ul: {
+ s: 1,
+ t: 4,
+ },
+ },
+ },
+ },
+ 38: {
+ 12: {
+ v: 'DASH LONG HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 5,
+ },
+ },
+ },
+ },
+ 40: {
+ 12: {
+ v: 'DOT DASH',
+ s: {
+ ul: {
+ s: 1,
+ t: 6,
+ },
+ },
+ },
+ },
+ 42: {
+ 12: {
+ v: 'DOT DOT DASH',
+ s: {
+ ul: {
+ s: 1,
+ t: 7,
+ },
+ },
+ },
+ },
+ 44: {
+ 12: {
+ v: 'DOTTED',
+ s: {
+ ul: {
+ s: 1,
+ t: 8,
+ },
+ },
+ },
+ },
+ 46: {
+ 12: {
+ v: 'DOTTED HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 9,
+ },
+ },
+ },
+ },
+ 48: {
+ 12: {
+ v: 'WAVE',
+ s: {
+ ul: {
+ s: 1,
+ t: 14,
+ },
+ },
+ },
+ },
+ 50: {
+ 12: {
+ v: 'WAVE HEAVY',
+ s: {
+ ul: {
+ s: 1,
+ t: 16,
+ },
+ },
+ },
+ },
+ 52: {
+ 12: {
+ v: 'THICK',
+ s: {
+ ul: {
+ s: 1,
+ t: 13,
+ },
+ },
+ },
+ },
},
freeze: {
@@ -14588,7 +14731,11 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
ah: 19,
},
},
- columnData: {},
+ columnData: {
+ 12: {
+ w: 180,
+ },
+ },
showGridlines: 1,
rowHeader: {
width: 46,
diff --git a/packages/engine-render/src/components/docs/extensions/line.ts b/packages/engine-render/src/components/docs/extensions/line.ts
index b5fce50160..fa34bd97ed 100644
--- a/packages/engine-render/src/components/docs/extensions/line.ts
+++ b/packages/engine-render/src/components/docs/extensions/line.ts
@@ -128,9 +128,8 @@ export class Line extends docExtension {
const color =
(c === BooleanNumber.TRUE ? getColorStyle(glyph.ts?.cl) : getColorStyle(colorStyle)) || COLOR_BLACK_RGB;
ctx.strokeStyle = color;
- ctx.lineWidth = lineWidth;
- this._setLineType(ctx, lineType || TextDecoration.SINGLE);
+ this._setLineType(ctx, lineType ?? TextDecoration.SINGLE, lineWidth);
const centerAngle = degToRad(centerAngleDeg);
const vertexAngle = degToRad(vertexAngleDeg);
@@ -151,24 +150,77 @@ export class Line extends docExtension {
ctx.beginPath();
ctx.moveTo(start.x, start.y);
- ctx.lineTo(end.x, end.y);
+ if (this._isWave(lineType)) {
+ for (let x = start.x; x < end.x; x++) {
+ ctx.lineTo(x, end.y + 1 * Math.sin(x * 1)); // y + amplitude * frequency
+ }
+ } else {
+ ctx.lineTo(end.x, end.y);
+ }
+
ctx.stroke();
ctx.restore();
}
- private _setLineType(ctx: UniverRenderingContext, style: TextDecoration) {
- if (style === TextDecoration.DASH_DOT_DOT_HEAVY || style === TextDecoration.DOT_DOT_DASH) {
- ctx.setLineDash([2, 2, 5, 2, 2]);
- } else if (style === TextDecoration.DASH_DOT_HEAVY || style === TextDecoration.DOT_DASH) {
- ctx.setLineDash([2, 5, 2]);
- } else if (style === TextDecoration.DOTTED || style === TextDecoration.DOTTED_HEAVY) {
- ctx.setLineDash([2]);
- } else if (style === TextDecoration.DASH || style === TextDecoration.DASHED_HEAVY) {
- ctx.setLineDash([3]);
- } else if (style === TextDecoration.DASH_LONG || style === TextDecoration.DASH_LONG_HEAVY) {
- ctx.setLineDash([6]);
- } else {
- ctx.setLineDash([0]);
+ private _isWave(lineType: TextDecoration | undefined): boolean {
+ return lineType === TextDecoration.WAVE || lineType === TextDecoration.WAVY_HEAVY;
+ }
+
+ private _setLineType(ctx: UniverRenderingContext, style: TextDecoration, lineWidth: number) {
+ switch (style) {
+ case TextDecoration.DOTTED:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2]);
+ return;
+ case TextDecoration.DOTTED_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2]);
+ return;
+ case TextDecoration.DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([3]);
+ return;
+ case TextDecoration.DASHED_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([3]);
+ return;
+ case TextDecoration.DASH_LONG:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([6]);
+ return;
+ case TextDecoration.DASH_LONG_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([6]);
+ return;
+ case TextDecoration.DOT_DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2, 5, 2]);
+ return;
+ case TextDecoration.DASH_DOT_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2, 5, 2]);
+ return;
+ case TextDecoration.DOT_DOT_DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2, 2, 5, 2, 2]);
+ return;
+ case TextDecoration.DASH_DOT_DOT_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2, 2, 5, 2, 2]);
+ return;
+ case TextDecoration.THICK:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([0]);
+ return;
+ case TextDecoration.WAVE:
+ ctx.lineWidth = 1;
+ return;
+ case TextDecoration.WAVY_HEAVY:
+ ctx.lineWidth = 2;
+ return;
+ default:
+ ctx.setLineDash([0]);
+ ctx.lineWidth = lineWidth;
}
}
}
diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.ts
index d75978553e..bafb7b323b 100644
--- a/packages/engine-render/src/components/sheets/extensions/font.ts
+++ b/packages/engine-render/src/components/sheets/extensions/font.ts
@@ -535,6 +535,7 @@ export class Font extends SheetExtension {
color: fontCache.style?.cl?.rgb,
strokeLine: Boolean(fontCache.style?.st?.s),
underline: Boolean(fontCache.style?.ul?.s),
+ underlineType: fontCache.style?.ul?.t,
cellValueType: cellData.t,
});
}
diff --git a/packages/engine-render/src/shape/text.ts b/packages/engine-render/src/shape/text.ts
index 03a992f10b..42b47357b5 100644
--- a/packages/engine-render/src/shape/text.ts
+++ b/packages/engine-render/src/shape/text.ts
@@ -17,7 +17,7 @@
import type { IKeyValue, Nullable } from '@univerjs/core';
import type { UniverRenderingContext } from '../context';
import type { IShapeProps } from './shape';
-import { CellValueType, HorizontalAlign, VerticalAlign } from '@univerjs/core';
+import { CellValueType, HorizontalAlign, TextDecoration, VerticalAlign } from '@univerjs/core';
import { COLOR_BLACK_RGB } from '../basics';
import { DocSimpleSkeleton } from '../components/docs/layout/doc-simple-skeleton';
import { Shape } from './shape';
@@ -33,6 +33,7 @@ export interface ITextProps extends IShapeProps {
color?: Nullable<string>;
strokeLine?: boolean;
underline?: boolean;
+ underlineType?: TextDecoration;
cellValueType?: Nullable<CellValueType>;
}
@@ -112,6 +113,7 @@ export class Text extends Shape<ITextProps> {
width: lineWidth,
color: props.color || '#000000',
lineWidth: 1,
+ lineType: props.underlineType ?? TextDecoration.SINGLE,
});
}
@@ -123,6 +125,7 @@ export class Text extends Shape<ITextProps> {
width: lineWidth,
color: props.color || '#000000',
lineWidth: 1,
+ lineType: TextDecoration.SINGLE,
});
}
@@ -143,20 +146,88 @@ export class Text extends Shape<ITextProps> {
width: number;
color: string;
lineWidth: number;
+ lineType: TextDecoration;
}) {
- const { x, y, width, color, lineWidth } = options;
+ const { x, y, width, color, lineWidth, lineType } = options;
ctx.save();
ctx.strokeStyle = color;
- ctx.lineWidth = lineWidth;
+ this._setLineType(ctx, lineType, lineWidth);
ctx.beginPath();
ctx.moveTo(x, y);
- ctx.lineTo(x + width, y);
+ if (this._isWave(lineType)) {
+ for (let x = 1; x < width + 1; x++) {
+ ctx.lineTo(x, y + 1 * Math.sin(x * 1)); // y + amplitude * frequency
+ }
+ } else {
+ ctx.lineTo(x + width, y);
+ }
ctx.stroke();
-
ctx.restore();
}
+ private static _setLineType(ctx: UniverRenderingContext, style: TextDecoration, lineWidth: number) {
+ switch (style) {
+ case TextDecoration.DOTTED:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2]);
+ return;
+ case TextDecoration.DOTTED_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2]);
+ return;
+ case TextDecoration.DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([3]);
+ return;
+ case TextDecoration.DASHED_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([3]);
+ return;
+ case TextDecoration.DASH_LONG:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([6]);
+ return;
+ case TextDecoration.DASH_LONG_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([6]);
+ return;
+ case TextDecoration.DOT_DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2, 5, 2]);
+ return;
+ case TextDecoration.DASH_DOT_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2, 5, 2]);
+ return;
+ case TextDecoration.DOT_DOT_DASH:
+ ctx.lineWidth = 1;
+ ctx.setLineDash([2, 2, 5, 2, 2]);
+ return;
+ case TextDecoration.DASH_DOT_DOT_HEAVY:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([2, 2, 5, 2, 2]);
+ return;
+ case TextDecoration.THICK:
+ ctx.lineWidth = 2;
+ ctx.setLineDash([0]);
+ return;
+ case TextDecoration.WAVE:
+ ctx.lineWidth = 1;
+ return;
+ case TextDecoration.WAVY_HEAVY:
+ ctx.lineWidth = 2;
+ return;
+ default:
+ ctx.setLineDash([0]);
+ ctx.lineWidth = lineWidth;
+ }
+ }
+
+ private static _isWave(lineType: TextDecoration): boolean {
+ return lineType === TextDecoration.WAVE || lineType === TextDecoration.WAVY_HEAVY;
+ }
+
protected override _draw(ctx: UniverRenderingContext) {
this.skeleton.calculate();
Text.drawWith(ctx, this, this.skeleton);