View | Details | Raw Unified | Return to bug 41076
Collapse All | Expand All

(-)WordExtractor.java (-65 / +39 lines)
Lines 135-207 Link Here
135
    List textRuns = cbt.getTextRuns();
135
    List textRuns = cbt.getTextRuns();
136
    Iterator runIt = textRuns.iterator();
136
    Iterator runIt = textRuns.iterator();
137
    Iterator textIt = textPieces.iterator();
137
    Iterator textIt = textPieces.iterator();
138
138
    
139
    TextPiece currentPiece = (TextPiece)textIt.next();
139
    if(!runIt.hasNext()) 
140
    int currentTextStart = currentPiece.getStart();
140
    	return "";
141
    int currentTextEnd = currentPiece.getEnd();
141
    
142
143
    WordTextBuffer finalTextBuf = new WordTextBuffer();
142
    WordTextBuffer finalTextBuf = new WordTextBuffer();
144
143
    
145
    // iterate through all text runs extract the text only if they haven't been
144
    // This code is built to handle all 6 cases of pieces and runs:
146
    // deleted
145
    // The two cases where there is no overlap.
147
    while (runIt.hasNext())
146
    // The two cases where one is completely contained in the other.
148
    {
147
    // The two cases where there is partial overlap.
149
      CHPX chpx = (CHPX)runIt.next();
148
    
150
      boolean deleted = isDeleted(chpx.getGrpprl());
149
    CHPX currRun = (CHPX) runIt.next();
151
      if (deleted)
150
    outer:
152
      {
151
    while(textIt.hasNext()) {
153
        continue;
152
    	TextPiece currPiece = (TextPiece) textIt.next();
154
      }
153
    	do {
155
154
    		// If all of the current run is after the current piece, go on to the next piece.
156
      int runStart = chpx.getStart();
155
    		if(currRun.getStart() >= currPiece.getEnd()) {
157
      int runEnd = chpx.getEnd();
156
    			continue outer;
158
157
    		}
159
      while (runStart >= currentTextEnd)
158
    		// If the current text run isn't deleted and this piece starts before the 
160
      {
159
    		// current run ends, there must be some overlap between these objects.
161
        currentPiece = (TextPiece) textIt.next ();
160
    		if(!isDeleted(currRun.getGrpprl()) && currPiece.getStart() < currRun.getEnd()) {
162
        currentTextStart = currentPiece.getStart ();
161
        		int startIndex = Math.max(currRun.getStart() - currPiece.getStart(), 0);
163
        currentTextEnd = currentPiece.getEnd ();
162
        		int endIndex = Math.min(currRun.getEnd(), currPiece.getEnd()) - currPiece.getStart();
164
      }
163
        		String str = currPiece.substring(startIndex, endIndex);
165
164
        		finalTextBuf.append(str);
166
      if (runEnd < currentTextEnd)
165
        		
167
      {
166
        		// if this run ends after the current piece ends, go on to the next piece
168
        String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
167
        		// while still using the current run.
169
        finalTextBuf.append(str);
168
        		if(currRun.getEnd() >= currPiece.getEnd()) {
170
      }
169
        			continue outer;
171
      else if (runEnd > currentTextEnd)
170
        		}
172
      {
171
    		}
173
        while (runEnd > currentTextEnd)
172
    		
174
        {
173
    		if(runIt.hasNext()) {
175
          String str = currentPiece.substring(runStart - currentTextStart,
174
        		currRun = (CHPX) runIt.next();
176
                                   currentTextEnd - currentTextStart);
175
    		}
177
          finalTextBuf.append(str);
176
    	}while(runIt.hasNext());
178
          if (textIt.hasNext())
179
          {
180
            currentPiece = (TextPiece) textIt.next ();
181
            currentTextStart = currentPiece.getStart ();
182
            runStart = currentTextStart;
183
            currentTextEnd = currentPiece.getEnd ();
184
          }
185
          else
186
          {
187
            return finalTextBuf.toString();
188
          }
189
        }
190
        String str = currentPiece.substring(0, runEnd - currentTextStart);
191
        finalTextBuf.append(str);
192
      }
193
      else
194
      {
195
        String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
196
        if (textIt.hasNext())
197
        {
198
          currentPiece = (TextPiece) textIt.next();
199
          currentTextStart = currentPiece.getStart();
200
          currentTextEnd = currentPiece.getEnd();
201
        }
202
        finalTextBuf.append(str);
203
      }
204
    }
177
    }
178
205
    return finalTextBuf.toString();
179
    return finalTextBuf.toString();
206
  }
180
  }
207
181

Return to bug 41076