Skip to content

Commit

Permalink
fix: no underline & strikeline when vertexangle is -90
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Oct 17, 2024
1 parent 2031d01 commit 712ca35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions packages/engine-render/src/components/docs/extensions/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/

import type { IScale, ITextDecoration } from '@univerjs/core';
import { BaselineOffset, BooleanNumber, getColorStyle, TextDecoration } from '@univerjs/core';
import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';

import type { UniverRenderingContext } from '../../../context';
import { BaselineOffset, BooleanNumber, getColorStyle, TextDecoration } from '@univerjs/core';
import { COLOR_BLACK_RGB, DEFAULT_OFFSET_SPACING, FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';
import { calculateRectRotate } from '../../../basics/draw';
import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';
import { degToRad, getScale } from '../../../basics/tools';
import { Vector2 } from '../../../basics/vector2';
import type { UniverRenderingContext } from '../../../context';
import { DocumentsSpanAndLineExtensionRegistry } from '../../extension';
import { docExtension } from '../doc-extension';

Expand All @@ -39,6 +39,12 @@ export class Line extends docExtension {

override draw(ctx: UniverRenderingContext, parentScale: IScale, glyph: IDocumentSkeletonGlyph) {
const line = glyph.parent?.parent;
const { renderConfig } = this.extensionOffset;
// rotation of cell text
// rotate up down 90 cause problem, univer-pro/issues/2802, This is only a temporary solution
const vertexAngle = renderConfig?.vertexAngle || 0;
const centerAngle = renderConfig?.centerAngle || 0;
const drawStrikeAndUnderline = !(centerAngle === 0 && vertexAngle !== 0 && vertexAngle % 90 === 0);
const { ts: textStyle, bBox, content } = glyph;

if (line == null || textStyle == null || content === '\r') {
Expand All @@ -51,7 +57,7 @@ export class Line extends docExtension {
const DELTA = 0.5;
const { ul: underline, st: strikethrough, ol: overline, va: baselineOffset, bbl: bottomBorderLine } = textStyle;

if (underline) {
if (drawStrikeAndUnderline && underline) {
const startY = asc + dsc;
this._drawLine(ctx, glyph, underline, startY, scale);
}
Expand All @@ -61,7 +67,7 @@ export class Line extends docExtension {
this._drawLine(ctx, glyph, bottomBorderLine, startY, scale, 2);
}

if (strikethrough) {
if (drawStrikeAndUnderline && strikethrough) {
// strikethrough position is the middle of bounding box ascent and descent.
let startY = asc + bd - strikeoutPosition - DELTA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class Font extends SheetExtension {
endX: number,
endY: number,
row: number,
column: number,
col: number,
overflowCache: ObjectMatrix<IRange>
) {
const documents = this.getDocuments() as Documents;
Expand All @@ -350,7 +350,7 @@ export class Font extends SheetExtension {

// Use fix https://github.com/dream-num/univer/issues/927, Set the actual width of the content to the page width of the document,
// so that the divide will be aligned when the skeleton is calculated.
const overflowRectangle = overflowCache.getValue(row, column);
const overflowRectangle = overflowCache.getValue(row, col);

const isOverflow = !(wrapStrategy === WrapStrategy.WRAP && !overflowRectangle && vertexAngle === 0);
if (isOverflow) {
Expand Down

0 comments on commit 712ca35

Please sign in to comment.