Applied image rendering fix to RichTextPane3.

Slightly fixed text selection in RichTextPane3.
This commit is contained in:
Snowyfox 2022-05-31 08:12:40 -04:00
parent d52879324f
commit 2b63e37276

View File

@ -345,14 +345,21 @@ implements
else if (node.key.equals("emoji"))
{
Image image = emojis.get(node.value);
if (image != null)
Image scaled = emojis.get(node.value + "_scaled");
if (scaled != null)
{
int ow = image.getWidth(this);
int oh = image.getHeight(this);
int nh = fm.getAscent() + fm.getDescent();
int nw = ow * nh/oh;
y -= asc;
g.drawImage(image, x, y, nw, nh, this);
g.drawImage(scaled, x, y, this);
}
else if (image != null)
{
scaled = image.getScaledInstance(
-1, fm.getAscent() + fm.getDescent(),
Image.SCALE_SMOOTH
);
// I hope #getScaledInstance knows how to
// wait if the image is yet to be loaded.
emojis.put(node.value + "_scaled", scaled);
}
else
{
@ -586,21 +593,26 @@ implements
// - -%- -
private static int
snap2(int value, int initial, int advance)
snap2(int blocks, int initial, int advance)
{
return initial + (value - 1) * advance;
return initial + (blocks - 1) * advance;
// If you'd like to go behind the first line 1,
// note that the first negative line is 0.
}
private static int
isnap2(int value, int initial, int advance)
isnap2(int units, int initial, int advance)
{
int offset = value - initial;
return 1 + ((offset - 1) / advance);
// Mostly correct for negative numbers. I just
// need this function to accept negative numbers,
// not give usable results.
int offset = units - initial;
return 2 + bfloor(offset - 1, advance);
// Not yet sure how this behaves for negative numbers.
}
private static int
bfloor(int units, int block)
{
if (units < 0) return (units / block) - 1;
else return units / block;
}
// ---%-@-%---