diff --git a/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java b/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java index 03022658c54..cb45be73f68 100644 --- a/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java +++ b/src/java.desktop/share/classes/sun/font/ExtendedTextSourceLabel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -493,10 +493,9 @@ class ExtendedTextSourceLabel extends ExtendedTextLabel implements Decoration.La --start; while (width >= -epsilon && ++start < length) { int cidx = l2v(start) * numvals + advx; - if (cidx >= charinfo.length) { - break; // layout bailed for some reason - } - float adv = charinfo[cidx]; + float adv = cidx < charinfo.length ? + charinfo[cidx] : // layout provided info for this glyph + 0; // glyph info omitted, assume no advance if (adv != 0) { width -= adv + advTracking; } diff --git a/src/java.desktop/share/native/libfontmanager/HBShaper.c b/src/java.desktop/share/native/libfontmanager/HBShaper.c index ffb3419286d..1da79bd78ed 100644 --- a/src/java.desktop/share/native/libfontmanager/HBShaper.c +++ b/src/java.desktop/share/native/libfontmanager/HBShaper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -272,6 +272,7 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape buffer = hb_buffer_create(); hb_buffer_set_script(buffer, getHBScriptCode(script)); + hb_buffer_set_invisible_glyph(buffer, INVISIBLE_GLYPH_ID); hb_buffer_set_language(buffer, hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE)); if ((flags & TYPO_RTL) != 0) { diff --git a/src/java.desktop/share/native/libfontmanager/HBShaper_Panama.c b/src/java.desktop/share/native/libfontmanager/HBShaper_Panama.c index de067736c8c..f6f4c357c31 100644 --- a/src/java.desktop/share/native/libfontmanager/HBShaper_Panama.c +++ b/src/java.desktop/share/native/libfontmanager/HBShaper_Panama.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -107,6 +107,7 @@ JDKEXPORT void jdk_hb_shape( buffer = hb_buffer_create(); hb_buffer_set_script(buffer, getHBScriptCode(script)); + hb_buffer_set_invisible_glyph(buffer, INVISIBLE_GLYPH_ID); hb_buffer_set_language(buffer, hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE)); if ((flags & TYPO_RTL) != 0) { diff --git a/src/java.desktop/share/native/libfontmanager/hb-jdk-p.h b/src/java.desktop/share/native/libfontmanager/hb-jdk-p.h index 890e3cabdd9..47d36e8b02f 100644 --- a/src/java.desktop/share/native/libfontmanager/hb-jdk-p.h +++ b/src/java.desktop/share/native/libfontmanager/hb-jdk-p.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, 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 @@ -48,6 +48,8 @@ extern "C" { #endif +// Matches sun.font.CharToGlyphMapper.INVISIBLE_GLYPH_ID +#define INVISIBLE_GLYPH_ID 0xffff hb_font_t* jdk_font_create_hbp( hb_face_t* face, diff --git a/src/java.desktop/share/native/libfontmanager/hb-jdk.h b/src/java.desktop/share/native/libfontmanager/hb-jdk.h index dc5788fc734..bf58bbf60e1 100644 --- a/src/java.desktop/share/native/libfontmanager/hb-jdk.h +++ b/src/java.desktop/share/native/libfontmanager/hb-jdk.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -50,6 +50,9 @@ typedef struct JDKFontInfo_Struct { #define HBFloatToFixedScale ((float)(1 << 16)) #define HBFloatToFixed(f) ((unsigned int)((f) * HBFloatToFixedScale)) +// Matches sun.font.CharToGlyphMapper.INVISIBLE_GLYPH_ID +#define INVISIBLE_GLYPH_ID 0xffff + /* * Note: * diff --git a/test/jdk/java/awt/font/TextLayout/FormatCharAdvanceTest.java b/test/jdk/java/awt/font/TextLayout/FormatCharAdvanceTest.java index d166a1b824b..b37f7e02707 100644 --- a/test/jdk/java/awt/font/TextLayout/FormatCharAdvanceTest.java +++ b/test/jdk/java/awt/font/TextLayout/FormatCharAdvanceTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8208377 6562489 + * @bug 8208377 6562489 8270265 * @summary Confirm that format-category glyphs are not rendered or measured. */ @@ -275,6 +275,12 @@ public class FormatCharAdvanceTest { g2d.drawString(as2.getIterator(), w / 2, h / 2); ab2 = findTextBoundingBox(image).width; assertEqual(ab1, ab2, "drawString (using AttributedCharacterIterator)", c, font); + + int max = metrics.stringWidth("AB") + 2; // add a little wiggle room to the max width + LineBreakMeasurer measurer1 = new LineBreakMeasurer(as1.getIterator(), frc); + LineBreakMeasurer measurer2 = new LineBreakMeasurer(as2.getIterator(), frc); + assertEqual(2, measurer1.nextOffset(max), "nextOffset 1", c, font); + assertEqual(7, measurer2.nextOffset(max), "nextOffset 2", c, font); } private static void assertEqual(int i1, int i2, String scenario, char c, Font font) {