⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixelrenderer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     PixelRenderer.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.interlinear;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.util.ArrayList;/** * This class renders pixel based interlinearized content. * * @author Han Sloetjes */public class PixelRenderer {    /**     * Renders the contents of the Interlinear object to the specified     * BufferedImage  using a horizontal and vertical offset.     *     * @param interlinear the <code>Interlinear</code> object     * @param bi the BufferedImage, the destination for rendering     * @param offset horizontal and vertical offset (shift)     */    public static void render(Interlinear interlinear, BufferedImage bi,        int[] offset) {        Graphics2D g2d = (Graphics2D) bi.getGraphics();        g2d.setColor(Color.LIGHT_GRAY);        g2d.fillRect(0, 0, bi.getWidth(), bi.getHeight());        int[] visibleRect = { bi.getWidth(), bi.getHeight() };        render(interlinear, g2d, offset, visibleRect);    }    /**     * Renders the contents of the specified page of the Interlinear object to     * the specified  Graphics object.     *     * @param interlinear the <code>Interlinear</code> object     * @param g the Graphics object, the destination for rendering     * @param pageIndex the index of the page to render     */    public static void render(Interlinear interlinear, Graphics g, int pageIndex) {        if ((pageIndex < 0) ||                (pageIndex >= interlinear.getMetrics().getPageBreaks().size())) {            return; // throw exception or return false        }        Graphics2D g2d = (Graphics2D) g;        int[] pageBreak = (int[]) interlinear.getMetrics().getPageBreaks().get(pageIndex);        g2d.setColor(Color.LIGHT_GRAY);        // margin        if (interlinear.isTierLabelsShown()) {            g2d.drawLine(interlinear.getMetrics().getLeftMargin(), 0,                interlinear.getMetrics().getLeftMargin(),                interlinear.getPageHeight());        }        int[] offset = { 0, 0 };        int[] visRect = { interlinear.getWidth(), interlinear.getHeight() };        renderPage(g2d, interlinear, pageBreak, offset, visRect, 0);    }    /**     * This pixel based renderer can render a preview of a character based     * linearization. Positions of tiers and annotations are converted to     * pixel values and they are rendered using a monospaced font.     *     * @param interlinear the <code>Interlinear</code> object containing the     *        data     * @param bi the BufferedImage to render to     * @param offset the horizontal and vertical (scroll) offset     */    public static void renderCharacterPreview(Interlinear interlinear,        BufferedImage bi, int[] offset) {        Graphics2D g2d = (Graphics2D) bi.getGraphics();        g2d.setColor(Color.WHITE);        g2d.fillRect(0, 0, bi.getWidth(), bi.getHeight());        g2d.setColor(Color.BLACK);        g2d.setFont(Interlinear.MONOSPACED_FONT);        g2d.translate(-offset[0], 0.0);        int[] visibleRect = { bi.getWidth(), bi.getHeight() };        renderCharacterPreview(interlinear, g2d, offset, visibleRect);    }    /**     * Renders the contents of the Interlinear object to the Graphics context     * using the specified horizontal and vertical offset, limiting the     * rendering  to the specified visible rectangle.     *     * @param interlinear the <code>Interlinear</code> object     * @param g2d the Graphics object, the destination for rendering     * @param offset horizontal and vertical offset (shift)     * @param visibleRect the visible rectangle     */    private static void render(Interlinear interlinear, Graphics2D g2d,        int[] offset, int[] visibleRect) {        // ignore the horizontal shift        int vertOffset = offset[1];        int firstVisPage = vertOffset / interlinear.getPageHeight(); // 0 based        g2d.setColor(Color.WHITE);        g2d.translate(-offset[0], 0);        g2d.fillRect(0, 0, interlinear.getWidth(), visibleRect[1]);        g2d.setColor(Color.LIGHT_GRAY);        // margin        if (interlinear.isTierLabelsShown()) {            g2d.drawLine(interlinear.getMetrics().getLeftMargin(), 0,                interlinear.getMetrics().getLeftMargin(), visibleRect[1]);        }        // page boundary markers		        g2d.translate(0.0, -vertOffset);        ArrayList breaks = interlinear.getMetrics().getPageBreaks();        for (int i = firstVisPage; i < breaks.size(); i++) {            g2d.drawLine(0, i * interlinear.getPageHeight(), visibleRect[0],                i * interlinear.getPageHeight());            //System.out.println("Draw page marker at: " + (i * interlinear.getPageHeight()));            if ((i * interlinear.getPageHeight()) > (offset[1] +                    visibleRect[1])) {                break;            }        }        // annotations        ArrayList blocks = interlinear.getMetrics().getPrintBlocks();        InterlinearBlock printBlock = null;        InterlinearTier pt = null;        int y = 0;pageloop:         for (int i = firstVisPage; i < breaks.size(); i++) {            int[] br = (int[]) breaks.get(i);            y = i * interlinear.getPageHeight();            if (y < (offset[1] + visibleRect[1])) {                //System.out.println("Page: " + i);                renderPage(g2d, interlinear, br, offset, visibleRect, y);                continue pageloop;            } else {                if ((1 + 1) == 2) {                    return;                }            }            // this is now obsolete, but not yet deleted            for (int j = br[0]; j <= br[2]; j++) {                printBlock = (InterlinearBlock) blocks.get(j);                ArrayList tiers = printBlock.getPrintTiers();                // line index var                int k = 0;                int maxK = printBlock.getNumberOfLines();                if (j == br[0]) {                    k = br[1];                }                if (j == br[2]) {                    maxK = br[3];                }tierloop:                 for (int count = k; count < tiers.size(); count++) {                    pt = (InterlinearTier) tiers.get(count);                    for (int z = 0; z < pt.getNumLines(); z++) {                        if (count > maxK) {                            continue pageloop;                            //break tierloop;                        }                        if (y >= vertOffset) {                            // paint the annotations                            //System.out.println("Print: Page: " + i + " Block: " + j + " Tier: " + pt.getTierName() + " line: " + z);                            renderTier(g2d, interlinear, pt, 0, y, z);                        }                        y += pt.getPrintHeight();                        if (y > (offset[1] + visibleRect[1])) {                            return;                        }                        if (z != (pt.getNumLines() - 1)) {                            y += interlinear.getLineSpacing();                        }                    }                    if (count != (tiers.size() - 1)) {                        y += interlinear.getLineSpacing();                    }                }                y += interlinear.getBlockSpacing();            }        }    }    /**     * Renders a page, as far it overlaps in the visible area.     *     * @param g2d the Graphics object, the destination for rendering     * @param interlinear the <code>Interlinear</code> object     * @param br the pagebreaks     * @param offset horizontal and vertical offset (shift)     * @param visibleRect the visible rectangle     * @param startYShift initial y position of page     */    private static void renderPage(Graphics2D g2d, Interlinear interlinear,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -