예제 #1
0
  @Override
  public List<Mark> getMarksForEntry(
      SourceTextEntry ste, String sourceText, String translationText, boolean isActive)
      throws Exception {

    if (!isEnabled()) {
      return null;
    }

    int srcGlyphMissing;
    if (isActive
        || Core.getEditor().getSettings().isDisplaySegmentSources()
        || translationText == null) {
      srcGlyphMissing = editorFont.canDisplayUpTo(sourceText);
    } else {
      srcGlyphMissing = -1;
    }

    int trgGlyphMissing = translationText == null ? -1 : editorFont.canDisplayUpTo(translationText);

    if (srcGlyphMissing == -1 && trgGlyphMissing == -1) {
      return null;
    }
    List<Mark> marks = new ArrayList<Mark>();
    if (srcGlyphMissing != -1) {
      createMarks(marks, Mark.ENTRY_PART.SOURCE, sourceText, srcGlyphMissing);
    }

    if (trgGlyphMissing != -1) {
      createMarks(marks, Mark.ENTRY_PART.TRANSLATION, translationText, trgGlyphMissing);
    }

    return marks;
  }
예제 #2
0
  @NotNull
  public static String getHtmlWithFonts(@NotNull String input, int style, @NotNull Font baseFont) {
    int start = baseFont.canDisplayUpTo(input);
    if (start == -1) return input;

    Font font = null;
    StringBuilder result = new StringBuilder();
    for (int i = start; i < input.length(); i++) {
      char c = input.charAt(i);
      if (baseFont.canDisplay(c)) {
        if (font != null) result.append("</font>");
        result.append(c);
        font = null;
      } else if (font != null && font.canDisplay(c)) {
        result.append(c);
      } else {
        if (font != null) result.append("</font>");
        font = getFontAbleToDisplay(c, baseFont.getSize(), style, baseFont.getFamily());
        if (font != baseFont) result.append("<font face=\"").append(font.getFamily()).append("\">");
        result.append(c);
      }
    }
    if (font != null) result.append("</font>");

    return result.toString();
  }
예제 #3
0
 private void createMarks(List<Mark> acc, Mark.ENTRY_PART part, String text, int firstMissing) {
   char[] chars = text.toCharArray();
   int i = firstMissing;
   while ((i = editorFont.canDisplayUpTo(chars, i, chars.length)) != -1) {
     int cp = Character.codePointAt(chars, i);
     int start = i;
     i += Character.charCount(cp);
     Font font = FontFallbackManager.getCapableFont(cp);
     if (font == null) {
       continue;
     }
     // Look ahead to try to group as many characters as possible into this run.
     for (int cpn, ccn, j = i; j < chars.length; j += ccn) {
       cpn = Character.codePointAt(chars, j);
       ccn = Character.charCount(cpn);
       if (!editorFont.canDisplay(cpn) && font.canDisplay(cpn)) {
         i += ccn;
       } else {
         break;
       }
     }
     Mark m = new Mark(part, start, i);
     m.attributes = getAttributes(font);
     acc.add(m);
   }
 }
예제 #4
0
  public Font getFont(String text, Locale locale) {
    int maxChars = -1;
    Font bestMatch = fontBundle.getFontFor(locale);
    if (bestMatch != null && (maxChars = bestMatch.canDisplayUpTo(text)) == -1) {
      return bestMatch;
    }

    for (Font font : fontBundle.getAllFonts()) {
      int upTo = font.canDisplayUpTo(text);
      if (upTo == -1) {
        return font;
      }
      if (upTo > maxChars) {
        bestMatch = font;
      }
    }
    return bestMatch;
  }
예제 #5
0
  private static boolean canDisplayMessage(Font f, Object msg) {
    boolean result = true;

    if (msg instanceof String) {
      String s = (String) msg;
      result = f.canDisplayUpTo(s) == -1;
    }

    return result;
  }
 private static boolean needFontFallback(Font font, String text) {
   return font.canDisplayUpTo(text) != -1
       && text.indexOf(CharacterIterator.DONE)
           == -1; // see IDEA-137517, TextLayout does not support this character
 }