mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
optimzation (?)
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@287 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
2f4f88c3dc
commit
2f820efca7
4 changed files with 16 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
public class ZLTextElement {
|
||||
class ZLTextElement {
|
||||
final static ZLTextElement HSpace = new ZLTextElement();
|
||||
|
||||
/* enum Kind {
|
||||
WORD_ELEMENT,
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
public class ZLTextHSpaceElement extends ZLTextElement {
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ public abstract class ZLTextParagraphCursor {
|
|||
Is spaceInserted variable used for inserting one separator instead of multiple spaces?*/
|
||||
|
||||
public void processTextEntry(ZLTextEntry textEntry) {
|
||||
final ZLTextElement hSpace = ZLTextElement.HSpace;
|
||||
int dataLength = textEntry.getDataLength();
|
||||
if (dataLength != 0) {
|
||||
final String data = textEntry.getData();
|
||||
|
@ -60,11 +61,11 @@ public abstract class ZLTextParagraphCursor {
|
|||
if (current == ' ') {
|
||||
if (firstNonSpace != -1) {
|
||||
addWord(data, firstNonSpace, charPos);
|
||||
myElements.add(new ZLTextHSpaceElement());
|
||||
myElements.add(hSpace);
|
||||
spaceInserted = true;
|
||||
firstNonSpace = -1;
|
||||
} else if (!spaceInserted) {
|
||||
myElements.add(new ZLTextHSpaceElement());
|
||||
myElements.add(hSpace);
|
||||
spaceInserted = true;
|
||||
}
|
||||
} else if (firstNonSpace == -1) {
|
||||
|
|
|
@ -75,8 +75,6 @@ public class ZLTextViewImpl extends ZLTextView {
|
|||
public int elementWidth(ZLTextElement element, int charNumber) {
|
||||
if (element instanceof ZLTextWord) {
|
||||
return wordWidth((ZLTextWord) element, charNumber, -1, false);
|
||||
} else if (element instanceof ZLTextHSpaceElement) {
|
||||
return 0;//myContext.getSpaceWidth();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -173,17 +171,17 @@ public class ZLTextViewImpl extends ZLTextView {
|
|||
ZLTextWordCursor cursor;
|
||||
for (cursor = info.Start; !cursor.equalWordNumber(info.End) && !cursor.isEndOfParagraph(); cursor.nextWord()) {
|
||||
ZLTextElement element = cursor.getElement();
|
||||
if (element instanceof ZLTextWord) {
|
||||
wordOccurred = true;
|
||||
ZLTextWord word = (ZLTextWord)element;
|
||||
context.drawString(w, h + info.Height, word.Data, word.Offset, word.Length);
|
||||
w += word.getWidth(context);
|
||||
} else if (element instanceof ZLTextHSpaceElement) {
|
||||
if (element == ZLTextElement.HSpace) {
|
||||
if (wordOccurred) {
|
||||
w += context.getSpaceWidth();
|
||||
spaces++;
|
||||
wordOccurred = false;
|
||||
}
|
||||
} else if (element instanceof ZLTextWord) {
|
||||
wordOccurred = true;
|
||||
ZLTextWord word = (ZLTextWord)element;
|
||||
context.drawString(w, h + info.Height, word.Data, word.Offset, word.Length);
|
||||
w += word.getWidth(context);
|
||||
} else if (element instanceof ZLTextControlElement) {
|
||||
myStyle.applyControl((ZLTextControlElement) element);
|
||||
}
|
||||
|
@ -278,17 +276,17 @@ public class ZLTextViewImpl extends ZLTextView {
|
|||
newWidth += myStyle.elementWidth(element, current.getCharNumber());
|
||||
newHeight = Math.max(newHeight, myStyle.elementHeight(element));
|
||||
newDescent = Math.max(newDescent, myStyle.elementDescent(element));
|
||||
if (element instanceof ZLTextWord) {
|
||||
wordOccurred = true;
|
||||
isVisible = true;
|
||||
//System.out.println("Word = " + ((ZLTextWord) element).Data + " FontSize = " + myStyle.getTextStyle().fontSize());
|
||||
} else if (element instanceof ZLTextHSpaceElement) {
|
||||
if (element == ZLTextElement.HSpace) {
|
||||
if (wordOccurred) {
|
||||
wordOccurred = false;
|
||||
internalSpaceCounter++;
|
||||
lastSpaceWidth = myStyle.getPaintContext().getSpaceWidth();
|
||||
newWidth += lastSpaceWidth;
|
||||
}
|
||||
} else if (element instanceof ZLTextWord) {
|
||||
wordOccurred = true;
|
||||
isVisible = true;
|
||||
//System.out.println("Word = " + ((ZLTextWord) element).Data + " FontSize = " + myStyle.getTextStyle().fontSize());
|
||||
} else if (element instanceof ZLTextControlElement) {
|
||||
myStyle.applyControl((ZLTextControlElement) element);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue