sun.font.Font2D Java Examples

The following examples show how to use sun.font.Font2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Font.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #2
Source File: Font.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #3
Source File: Font.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #4
Source File: Font.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #5
Source File: Font.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #6
Source File: Font.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #7
Source File: Font.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #8
Source File: Font.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Font(File fontFile, int fontFormat,
             boolean isCopy, CreatedFontTracker tracker)
    throws FontFormatException {
    this.createdFont = true;
    /* Font2D instances created by this method track their font file
     * so that when the Font2D is GC'd it can also remove the file.
     */
    FontManager fm = FontManagerFactory.getInstance();
    Font2D[] fonts =
        fm.createFont2D(fontFile, fontFormat, false, isCopy, tracker);
    this.font2DHandle = fonts[0].handle;
    this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault());
    this.style = Font.PLAIN;
    this.size = 1;
    this.pointSize = 1f;
}
 
Example #9
Source File: Font.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #10
Source File: Font.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #11
Source File: Font.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #12
Source File: Font.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #13
Source File: Font.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #14
Source File: Font.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #15
Source File: Font.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #16
Source File: Font.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #17
Source File: Font.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #18
Source File: Font.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #19
Source File: Font.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #20
Source File: Font.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Indicates whether or not this {@code Font} can display a
 * specified {@code String}.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the {@code String}
 * {@code str} which is the first character this
 * {@code Font} cannot display without using the missing glyph
 * code. If the {@code Font} can display all characters, -1 is
 * returned.
 * @param str a {@code String} object
 * @return an offset into {@code str} that points
 *          to the first character in {@code str} that this
 *          {@code Font} cannot display; or {@code -1} if
 *          this {@code Font} can display all characters in
 *          {@code str}.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #21
Source File: Font.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #22
Source File: Font.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #23
Source File: Font.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #24
Source File: Font.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display the
 * text specified by the <code>iter</code> starting at
 * <code>start</code> and ending at <code>limit</code>.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              <code>CharacterIterator</code>.
 * @param limit the specified ending offset into the specified
 *              <code>CharacterIterator</code>.
 * @return an offset into <code>iter</code> that points
 *          to the first character in <code>iter</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>iter</code>.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #25
Source File: Font.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #26
Source File: NotoSans.java    From java-9-wtf with Apache License 2.0 6 votes vote down vote up
public static Object createScaler() throws ReflectiveOperationException {
	// these APIs are used to reproduce the specific case I encountered
	// as closely as possible
	Font2D font = FontUtilities.getFont2D(new Font("Noto Sans CJK JP Black", 0, 12));

	// this is a reconstruction of what happens at the end of a call stack like:
	//  - BasicListUI.updateLayoutState()
	//  - JComponent.getPreferredSize()
	//  - JComponent.getFontMetrics(Font)
	//  - TrueTypeFont.getScaler
	Constructor<?> constructor = Class
			.forName("sun.font.T2KFontScaler")
			.getConstructor(Font2D.class, int.class, boolean.class, int.class);
	constructor.setAccessible(true);
	return constructor.newInstance(font, 0, true, 18604592);
}
 
Example #27
Source File: Font.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #28
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}
 
Example #29
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Indicates whether or not this <code>Font</code> can display a
 * specified <code>String</code>.  For strings with Unicode encoding,
 * it is important to know if a particular font can display the
 * string. This method returns an offset into the <code>String</code>
 * <code>str</code> which is the first character this
 * <code>Font</code> cannot display without using the missing glyph
 * code. If the <code>Font</code> can display all characters, -1 is
 * returned.
 * @param str a <code>String</code> object
 * @return an offset into <code>str</code> that points
 *          to the first character in <code>str</code> that this
 *          <code>Font</code> cannot display; or <code>-1</code> if
 *          this <code>Font</code> can display all characters in
 *          <code>str</code>.
 * @since 1.2
 */
public int canDisplayUpTo(String str) {
    Font2D font2d = getFont2D();
    int len = str.length();
    for (int i = 0; i < len; i++) {
        char c = str.charAt(i);
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        if (!font2d.canDisplay(str.codePointAt(i))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
Example #30
Source File: Font.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Font2D getFont2D() {
    FontManager fm = FontManagerFactory.getInstance();
    if (fm.usingPerAppContextComposites() &&
        font2DHandle != null &&
        font2DHandle.font2D instanceof CompositeFont &&
        ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
        return fm.findFont2D(name, style,
                                      FontManager.LOGICAL_FALLBACK);
    } else if (font2DHandle == null) {
        font2DHandle =
            fm.findFont2D(name, style,
                          FontManager.LOGICAL_FALLBACK).handle;
    }
    /* Do not cache the de-referenced font2D. It must be explicitly
     * de-referenced to pick up a valid font in the event that the
     * original one is marked invalid
     */
    return font2DHandle.font2D;
}