/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ package org.apache.openoffice.ooxml.viewer.tokenview; import java.awt.Graphics2D; import java.util.Iterator; import java.util.Vector; public class Line implements Iterable> { Line () { maRuns = new Vector>(); mnWidth = -1; mnHeight = -1; mnY = -1; mnStartOffset = -1; mnEndOffset = -1; } public void AddRun (final Run aRun) { maRuns.add(aRun); mnWidth += aRun.GetWidth(); if (aRun.GetHeight() > mnHeight) mnHeight = aRun.GetHeight(); aRun.SetLine(this); if (aRun.GetStreamOffset() >= 0) { if (mnStartOffset < 0) mnStartOffset = aRun.GetStreamOffset(); if (mnEndOffset < aRun.GetStreamEndOffset()) mnEndOffset = aRun.GetStreamEndOffset(); } } public void Format ( final Graphics2D aG2, final int nY) { mnY = nY; mnWidth = 0; mnHeight = 0; for (final Run aRun : maRuns) { aRun.Format(aG2); mnWidth += aRun.GetWidth(); if (mnHeight < aRun.GetHeight()) mnHeight = aRun.GetHeight(); } } public int GetWidth () { return mnWidth; } public int GetHeight () { return mnHeight; } public int GetTop () { return mnY; } public int GetBottom () { return mnY + mnHeight; } public boolean Overlaps ( final double nTop, final double nBottom) { return mnY<=nBottom && mnY+mnHeight>nTop; } public boolean Contains (final int nY) { return nY>=mnY && nY> iterator() { return maRuns.iterator(); } public Run GetRunForX (final int nX) { int nRunX = 0; for (final Run aRun : maRuns) { final int nRunWidth = aRun.GetWidth(); final int nRight = nRunX + nRunWidth; if (nX>=nRunX && nX GetRunForOffset (int nOffset) { for (int nIndex=0; nIndex aRun = maRuns.get(nIndex); final int nRunOffset = aRun.GetStreamOffset(); if (nRunOffset >= 0) if (nRunOffset<=nOffset && nOffset<=aRun.GetStreamEndOffset()) return aRun; } return null; } public Iterable> GetRunsForOffsets ( final int nStartOffset, final int nEndOffset) { final Vector> aRuns = new Vector<>(); for (final Run aRun : maRuns) { if (aRun.GetStreamOffset() >= nEndOffset) break; else if (aRun.GetStreamEndOffset()> maRuns; private int mnY; private int mnWidth; private int mnHeight; private int mnStartOffset; private int mnEndOffset; }