Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #1889

Merged
merged 2 commits into from
Jan 2, 2025
Merged

Release #1889

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion __tests__/demos/bugfix/textWordWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function textWordWrap(context: { canvas: Canvas }) {
textBaseline: 'top',
textOverflow: 'ellipsis',
wordWrap: true,
wordWrapWidth: 30,
wordWrapWidth: 84,
},
});
const rect2 = new Rect({
Expand All @@ -103,12 +103,43 @@ export async function textWordWrap(context: { canvas: Canvas }) {
},
});

const text3 = new Text({
style: {
x: 300,
y: 300,
wordWrap: true,
wordWrapWidth: 2,
maxLines: 5,
textOverflow: 'ellipsis',
fontFamily: 'Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif',
fontSize: 12,
fontWeight: 700,
fill: '#000000',
opacity: 1,
textAlign: 'center',
textBaseline: 'middle',
linkTextFill: '#326EF4',
text: '千亿数据',
},
});
const rect3 = new Rect({
style: {
x: text3.style.x,
y: text3.style.y,
width: text3.style.wordWrapWidth,
height: +text3.style.fontSize * text3.style.maxLines,
stroke: '#000000',
},
});

canvas.appendChild(text0);
canvas.appendChild(rect0);
canvas.appendChild(text1);
canvas.appendChild(rect1);
canvas.appendChild(text2);
canvas.appendChild(rect2);
canvas.appendChild(text3);
canvas.appendChild(rect3);

// benchmark
// ----------
Expand Down
7 changes: 7 additions & 0 deletions packages/g-camera-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-camera-api

## 2.0.33

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 2.0.32

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-camera-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-camera-api",
"version": "2.0.32",
"version": "2.0.33",
"description": "A simple implementation of Camera API.",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvas

## 2.0.37

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14
- @antv/g-plugin-canvas-path-generator@2.1.14
- @antv/g-plugin-canvas-picker@2.1.16
- @antv/g-plugin-canvas-renderer@2.2.16
- @antv/g-plugin-dom-interaction@2.1.19
- @antv/g-plugin-html-renderer@2.1.19
- @antv/g-plugin-image-loader@2.1.16

## 2.0.36

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "2.0.36",
"version": "2.0.37",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvaskit

## 1.0.36

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14
- @antv/g-plugin-canvas-path-generator@2.1.14
- @antv/g-plugin-canvas-picker@2.1.16
- @antv/g-plugin-canvaskit-renderer@2.1.16
- @antv/g-plugin-dom-interaction@2.1.19
- @antv/g-plugin-html-renderer@2.1.19
- @antv/g-plugin-image-loader@2.1.16

## 1.0.35

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "1.0.35",
"version": "1.0.36",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-components

## 2.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 2.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-components",
"version": "2.0.29",
"version": "2.0.30",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-dom-mutation-observer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-dom-mutation-observer-api

## 2.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 2.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-dom-mutation-observer-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-dom-mutation-observer-api",
"version": "2.0.29",
"version": "2.0.30",
"description": "A simple implementation of DOM MutationObserver API.",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-gesture

## 3.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 3.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "3.0.29",
"version": "3.0.30",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-image-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-image-exporter

## 1.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 1.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-image-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-image-exporter",
"version": "1.0.29",
"version": "1.0.30",
"description": "A image exporter for G using DOM API",
"keywords": [
"antv",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-lite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-lite

## 2.2.14

### Patch Changes

- 9d6fd39: fix: multi-line text wrapping exception

## 2.2.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lite",
"version": "2.2.13",
"version": "2.2.14",
"description": "A core module for rendering engine implements DOM API.",
"keywords": [
"antv",
Expand Down
48 changes: 29 additions & 19 deletions packages/g-lite/src/services/TextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export class TextService {
let lines: string[] = [];
let currentLineIndex = 0;
let currentLineWidth = 0;
let prevLineLastCharIndex = 0;

const cache: { [key in string]: number } = {};
const calcWidth = (txt: string): number => {
Expand All @@ -377,32 +378,37 @@ export class TextService {
*
* @see https://github.com/antvis/G/issues/1833
*
* @param txt - Current line of text
* @param textCharIndex - The index of the last character of the current line in the entire text
* @param lineTxt - Current line of text
* @param txtLastCharIndex - The index of the last character of the current line in the entire text
* @param txtStartCharIndex - The index of the start character of the current line in the entire text
*/
function findCharIndexClosestWidthThreshold(
txt: string,
textCharIndex: number,
lineTxt: string,
txtLastCharIndex: number,
txtStartCharIndex: number,
widthThreshold: number,
) {
while (
calcWidth(txt) < widthThreshold &&
textCharIndex < chars.length - 1
calcWidth(lineTxt) < widthThreshold &&
txtLastCharIndex < chars.length - 1
) {
if (self.isNewline(chars[textCharIndex + 1])) {
if (self.isNewline(chars[txtLastCharIndex + 1])) {
break;
}
textCharIndex += 1;
txt += chars[textCharIndex];
txtLastCharIndex += 1;
lineTxt += chars[txtLastCharIndex];
}
while (calcWidth(txt) > widthThreshold && textCharIndex > 0) {
textCharIndex -= 1;
txt = txt.slice(0, -1);
while (
calcWidth(lineTxt) > widthThreshold &&
txtLastCharIndex > txtStartCharIndex
) {
txtLastCharIndex -= 1;
lineTxt = lineTxt.slice(0, -1);
}

return {
txt,
textCharIndex,
lineTxt,
txtLastCharIndex,
};
}

Expand All @@ -422,10 +428,11 @@ export class TextService {
const result = findCharIndexClosestWidthThreshold(
lines[lineIndex],
textCharIndex,
prevLineLastCharIndex + 1,
maxWidth - ellipsisWidth,
);

lines[lineIndex] = result.txt + ellipsis;
lines[lineIndex] = result.lineTxt + ellipsis;
}

for (let i = 0; i < chars.length; i++) {
Expand All @@ -446,6 +453,7 @@ export class TextService {
break;
}

prevLineLastCharIndex = i - 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The introduction of prevLineLastCharIndex is a critical change to ensure that the character indexing is correctly managed across lines. This prevents potential off-by-one errors when calculating line breaks.

currentLineIndex += 1;
currentLineWidth = 0;
lines[currentLineIndex] = '';
Expand All @@ -457,16 +465,17 @@ export class TextService {
const result = findCharIndexClosestWidthThreshold(
lines[currentLineIndex],
i - 1,
prevLineLastCharIndex + 1,
maxWidth,
);
if (result.textCharIndex !== i - 1) {
lines[currentLineIndex] = result.txt;
if (result.txtLastCharIndex !== i - 1) {
lines[currentLineIndex] = result.lineTxt;

if (result.textCharIndex === chars.length - 1) {
if (result.txtLastCharIndex === chars.length - 1) {
break;
}

i = result.textCharIndex + 1;
i = result.txtLastCharIndex + 1;
char = chars[i];
prevChar = chars[i - 1];
nextChar = chars[i + 1];
Expand All @@ -481,6 +490,7 @@ export class TextService {
break;
}

prevLineLastCharIndex = i - 1;
currentLineIndex += 1;
currentLineWidth = 0;
lines[currentLineIndex] = '';
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lottie-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-lottie-player

## 1.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 1.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lottie-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lottie-player",
"version": "1.0.29",
"version": "1.0.30",
"description": "A lottie player for G",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-mobile-canvas-element/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-mobile-canvas-element

## 1.0.30

### Patch Changes

- Updated dependencies [9d6fd39]
- @antv/g-lite@2.2.14

## 1.0.29

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-canvas-element/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-canvas-element",
"version": "1.0.29",
"version": "1.0.30",
"description": "Create a CanvasLike element from existed context in mobile environment",
"keywords": [
"antv",
Expand Down
Loading
Loading