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

StubTextLayout #1667

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,7 @@

package com.sun.javafx.scene.text;

import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.javafx.geom.Point2D;
import com.sun.javafx.geom.RectBounds;

Expand Down Expand Up @@ -93,5 +94,25 @@ public interface GlyphList {
* can be null (for non-rich text) but never null for rich text.
*/
public TextSpan getTextSpan();

/**
* Returns true if this GlyphList is a line break.
* @return whether this GlyphList is a line break
*/
public boolean isLinebreak();

/**
* Returns the start offset.
* @return the start offset
*/
public int getStart();

/**
* Gets the glyph offset at the specified x coordinate.
* @param x the x coordinate
* @param trailing the reference to hold the trailing flag
* @return the glyph offset
*/
public int getOffsetAtX(float x, AtomicBoolean trailing);
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface TextSpan {
public Object getFont();

/**
* The bounds for embedded object, only used the font returns null.
* The bounds for embedded object, only used when the font returns null.
* The text for a embedded object should be a single char ("\uFFFC" is
* recommended).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicBoolean;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.PathElement;
Expand Down Expand Up @@ -448,9 +449,9 @@ public Hit getHitInfo(float x, float y) {
}
}
if (run != null) {
int[] trailing = new int[1];
AtomicBoolean trailing = new AtomicBoolean();
charIndex = run.getStart() + run.getOffsetAtX(x, trailing);
leading = (trailing[0] == 0);
leading = !trailing.get();

insertionIndex = charIndex;
if (getText() != null && insertionIndex < getText().length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.sun.javafx.text;

import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.javafx.font.CharToGlyphMapper;
import com.sun.javafx.geom.Point2D;
import com.sun.javafx.geom.RectBounds;
Expand Down Expand Up @@ -78,6 +79,7 @@ public TextRun(int start, int length, byte level, boolean complex,
if (canonical) flags |= FLAGS_CANONICAL;
}

@Override
public int getStart() {
return start;
}
Expand Down Expand Up @@ -114,6 +116,7 @@ public int getSlot() {
return slot;
}

@Override
public boolean isLinebreak() {
return (flags & FLAGS_LINEBREAK) != 0;
}
Expand Down Expand Up @@ -401,39 +404,36 @@ public float getXAtOffset(int offset, boolean leading) {
return 0; //line break
}

public int getGlyphAtX(float x, int[] trailing) {
public int getGlyphAtX(float x, AtomicBoolean trailing) {
boolean ltr = isLeftToRight();
float runX = 0;
for (int i = 0; i < glyphCount; i++) {
float advance = getAdvance(i);
if (runX + advance >= x) {
if (trailing != null) {
//TODO handle clusters
if (x - runX > advance / 2) {
trailing[0] = ltr ? 1 : 0;
} else {
trailing[0] = ltr ? 0 : 1;
}
//TODO handle clusters
if (x - runX > advance / 2) {
trailing.set(ltr ? true : false);
} else {
trailing.set(ltr ? false : true);
}
return i;
}
runX += advance;
}
if (trailing != null) trailing[0] = ltr ? 1 : 0;
trailing.set(ltr ? true : false);
return Math.max(0, glyphCount - 1);
}

public int getOffsetAtX(float x, int[] trailing) {
@Override
public int getOffsetAtX(float x, AtomicBoolean trailing) {
if (glyphCount > 0) {
int glyphIndex = getGlyphAtX(x, trailing);
return getCharOffset(glyphIndex);
}
/* tab */
if (width != -1 && length > 0) {
if (trailing != null) {
if (x > width / 2) {
trailing[0] = 1;
}
if (x > width / 2) {
trailing.set(true);
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ public final HitInfo hitTest(Point2D point) {
private int findFirstRunStart() {
int start = Integer.MAX_VALUE;
for (GlyphList r: getRuns()) {
int runStart = ((TextRun) r).getStart();
int runStart = r.getStart();
if (runStart < start) {
start = runStart;
}
Expand Down
Loading