📄 pixelrenderer.java
字号:
int[] br, int[] offset, int[] visibleRect, int startYShift) { // annotations ArrayList blocks = interlinear.getMetrics().getPrintBlocks(); InterlinearBlock printBlock = null; InterlinearTier pt = null; int y = startYShift; for (int j = br[0]; j <= br[2]; j++) { printBlock = (InterlinearBlock) blocks.get(j); ArrayList tiers = printBlock.getPrintTiers(); // total line counter in this block int lineNum = 0; // line index var, min and max int k = 0; int maxK = printBlock.getNumberOfLines(); if (j == br[0]) { k = br[1]; } if (j == br[2]) { maxK = br[3]; }//System.out.println("K: " + k + " max-K: " + maxK);tierloop: for (int tierCount = 0; tierCount < tiers.size(); tierCount++) { pt = (InterlinearTier) tiers.get(tierCount); for (int tierLine = 0; tierLine < pt.getNumLines(); tierLine++) { if (lineNum < k) { lineNum++; continue; } if (lineNum > maxK) { return; } if (y >= offset[1]) { // paint the annotations //System.out.println("Print: Block: " + j + " Tier: " + pt.getTierName() + " line: " + tierLine); renderTier(g2d, interlinear, pt, 0, y, tierLine); } y += pt.getPrintHeight(); if (y > (offset[1] + visibleRect[1])) { return; } if (tierLine != (pt.getNumLines() - 1)) { y += interlinear.getLineSpacing(); } lineNum++; } if (tierCount != (tiers.size() - 1)) { y += interlinear.getLineSpacing(); } } y += interlinear.getBlockSpacing(); } } /** * Render the contents of a InterlinearTier, called per line. * * @param g2d the Graphics object, the destination for rendering * @param interlinear the <code>Interlinear</code> object * @param pt the print tier holding the annotations * @param xShift horizontal shift * @param yShift the y-coord of the top of the tier * @param line the line (index) to render */ private static void renderTier(Graphics2D g2d, Interlinear interlinear, InterlinearTier pt, int xShift, int yShift, int line) { yShift += pt.getPrintHeight(); g2d.setFont(interlinear.getFont(pt.getTierName())); if (interlinear.isTierLabelsShown() && (line == 0)) { g2d.setColor(Color.LIGHT_GRAY); if (pt.isTimeCode()) { g2d.drawString(interlinear.getMetrics().TC_TIER_NAME, xShift, yShift - g2d.getFontMetrics().getDescent()); } else { g2d.drawString(pt.getTierName(), xShift, yShift - g2d.getFontMetrics().getDescent()); } } if (pt.isTimeCode()) { g2d.setColor(Color.RED); } else { g2d.setColor(Color.BLACK); } xShift += interlinear.getMetrics().getLeftMargin(); ArrayList annos = pt.getAnnotations(); InterlinearAnnotation pa = null; for (int i = 0; i < annos.size(); i++) { pa = (InterlinearAnnotation) annos.get(i); if (pa.nrOfLines == 1) { g2d.drawString(pa.getValue(), xShift + pa.x, yShift - g2d.getFontMetrics().getDescent()); // test drawing of outlines // g2d.drawRect(xShift + pa.x, yShift - pt.getPrintHeight(), pa.calcWidth, pt.getPrintHeight()); if (interlinear.isEmptySlotsShown() && pa.getValue().equals("")) { g2d.setColor(Color.GRAY); g2d.drawRect(xShift + pa.x, yShift - pt.getPrintHeight() + 1, pa.calcWidth, pt.getPrintHeight() - 2); g2d.setColor(Color.BLACK); } } else { int y = yShift - g2d.getFontMetrics().getDescent(); if (line < pa.getLines().length) { g2d.drawString(pa.getLines()[line], xShift + pa.x, y); } } } } /** * Renders a character based interlinearization to the given graphics * object by converting char position to pixel positions. * * @param interlinear the <code>Interlinear</code> object containing the * data * @param g2d the graphics context to render to * @param offset the horizontal and vertical (scroll) offset * @param visibleRect the visible area, used to prevent unnecessary paint * operations */ private static void renderCharacterPreview(Interlinear interlinear, Graphics2D g2d, int[] offset, int[] visibleRect) { int charWidth = g2d.getFontMetrics().charWidth('w'); int vertOffset = offset[1]; g2d.translate(0.0, -vertOffset); // annotations ArrayList blocks = interlinear.getMetrics().getPrintBlocks(); InterlinearBlock printBlock = null; ArrayList tiers = null; InterlinearTier pt = null; int y = 0; for (int i = 0; i < blocks.size(); i++) { printBlock = (InterlinearBlock) blocks.get(i); tiers = printBlock.getPrintTiers(); if ((y + (printBlock.getNumberOfLines() * Interlinear.DEFAULT_FONT_SIZE)) > vertOffset) { // render this block for (int j = 0; j < tiers.size(); j++) { pt = (InterlinearTier) tiers.get(j); renderCharTier(g2d, interlinear, pt, charWidth, y); y += (pt.getNumLines() * Interlinear.DEFAULT_FONT_SIZE); } } else { y += (printBlock.getNumberOfLines() * Interlinear.DEFAULT_FONT_SIZE); } y += (interlinear.getBlockSpacing() * Interlinear.DEFAULT_FONT_SIZE); if (y > (vertOffset + visibleRect[1])) { return; } } } /** * Renders a complete InterlinearTier, including tierlabel and multi line * annotations, using a monospaced font. * * @param g2d the graphics context * @param interlinear the <code>Interlinear</code> object containing the * data * @param pt the <code>InterlinearTier</code> holding the label and * formatted annotations * @param charWidth the width in pixels per character (it is a monospaced * font * @param yShift the y position of the print tier, the y coordinate of the * bounding box of the text */ private static void renderCharTier(Graphics2D g2d, Interlinear interlinear, InterlinearTier pt, int charWidth, int yShift) { yShift += Interlinear.DEFAULT_FONT_SIZE; int xShift = 0; if (interlinear.isTierLabelsShown()) { if (pt.isTimeCode()) { g2d.drawString(interlinear.getMetrics().TC_TIER_NAME, xShift, yShift - g2d.getFontMetrics().getDescent()); } else { g2d.drawString(pt.getTierName(), xShift, yShift - g2d.getFontMetrics().getDescent()); } xShift = interlinear.getMetrics().getLeftMargin() * charWidth; } ArrayList annos = pt.getAnnotations(); InterlinearAnnotation pa = null; for (int i = 0; i < annos.size(); i++) { pa = (InterlinearAnnotation) annos.get(i); if (pa.nrOfLines == 1) { g2d.drawString(pa.getValue(), xShift + (pa.x * charWidth), yShift - g2d.getFontMetrics().getDescent()); // test drawing of outlines // g2d.drawRect(xShift + (pa.x * charWidth), yShift - pt.getPrintHeight(), // (pa.calcWidth * charWidth), pt.getPrintHeight()); } else { int y = yShift - g2d.getFontMetrics().getDescent(); for (int line = 0; line < pa.getLines().length; line++) { g2d.drawString(pa.getLines()[line], xShift + (pa.x * charWidth), y); y += Interlinear.DEFAULT_FONT_SIZE; } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -