-
Notifications
You must be signed in to change notification settings - Fork 369
How can I get the number of lines of text? #50
Comments
@object1984 The number of lines is stored in there but I have not made it accessible yet. Will do that in the next 2 days. Hold tight. |
How much can I get the page number of rows to display it 2015-01-07 13:47 GMT+08:00 Mathew Kurian notifications@github.com:
|
To get the line count: DocumentView documentView;
Log.d("LineCount", Integer.toString(documentView.getLineCount()); To draw a certain area of text. // Page dimensions
float pageHeight = 600;
float pageWidth = 400;
// Create and setup layout
IDocumentLayout documentLayout = new StringDocumentLayout(this, new TextPaint());
documentLayout.setText("Large text input");
documentLayout.getLayoutParams().setParentWidth(pageWidth);
documentLayout.measure(new IDocumentLayout.ISet<Float>() {
@Override
public void set(Float val) {
Log.d("progress", val.toString());
}
}, new IDocumentLayout.IGet<Boolean>() {
@Override
public Boolean get() {
return true; // don't ever cancel the process
}
});
// Create bitmap
Bitmap bitmap = Bitmap.createBitmap((int) pageWidth, (int) pageHeight, Bitmap.Config.ARGB_8888);
// If you only want text between 30 and 100
int drawStartY = 30;
int drawEndY = 100;
documentLayout.draw(new Canvas(bitmap), drawStartY, drawEndY); |
so i should devide large text and i should paginate. |
Paginating is up to you. Depends on how you use it. If you the provided |
Let me expand. You can give DocumentLayout a very large text. Imagine it is // To get Y
Y = documentLayout.getMeasuredHeight();
// Page 1
documentLayout.draw(canvas, 0, Apx); // A < Y
// Page 2
documentLayout.draw(canvas, Apx, Bpx); // A < B < Y
// Page 3
documentLayout.draw(canvas, Bpx, Ypx); // B < Y The important thing to note is that |
if i create new documentLayout for each page, i should define how many text fill the documentLaoyut (for current screen size). for example: i give 90 words to documentLayout, i check, it's not filled, i give 95 words and i check, i give 100 words and it's filled, second page will begin from 101'st word |
@jamshid88 You don't need to do that in this case because you can give DocumentLayout all the text at once. You tell documentlayout how wide your screen is. Then it will fill it with text. When it finishes, you will get how tall the text is. That means you know how many pages you need. documentLayout.setText(myLongText);
documentLayout.getLayoutParams().setParentWidth(getScreenWidth());
documentLayout.measure(progress, cancel);
float measuredHeight = documentLayout.getMeasuredHeight();
// At least 1 page
Log.d("I need this many pages", Math.max(1, measuredHeight / getScreenHeight())); PS: I recommend updating to 2.0.4. Make sure to migrate the code as necessary. Minor changes which improve readability and one major bug fix. |
if i give 0 to drawStartY (startTop) and drawEndY(startBottom), nothing changed. (build: 2.0.4) // If you only want text between 30 and 100 |
What do you mean nothing changed? |
@bluejamesbond mesaureHeight is normally worked. |
@bluejamesbond |
Interesting. Can you provide me with some code to debug. |
/**
* set the text with justify style
*
* @param text
* @param canvas
*/
private void setTextAndJustify(CharSequence text, Canvas canvas) {
documentLayout.setText(text);
// documentLayout.getLayoutParams().setReverse(true);
documentLayout.getLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
documentLayout.measure(new IDocumentLayout.IProgress<Float>() {
@Override
public void onUpdate(Float val) {
Log.d("progress", val.toString());
}
}, new IDocumentLayout.ICancel<Boolean>() {
@Override
public Boolean isCancelled() {
return false;
}
});
documentLayout.draw(canvas);
} |
Can you provide me the full code? |
if curl the page, loadBitmap method will work. /**
|
@jamshid88 Can you provide |
we have large text, if we paginate, save start and end of page index on the text. so they saved numbers. |
@jamshid88 I need to see where you invoke |
you can see, documentLayout.draw and documentLayout.measure in setTextAndJustify() if it's complicated, i can try to give you project /**
|
Can you provide me the project? |
if text start with the space, 2 nd symbol deleted, if i cut the space(symbol) everythinng ok. Now, everything working. Thank you for the project and for your job and for your time! |
Your most welcome. But that is interesting. Can you provide me with some screenshots? I would like to fix this issue for the future. Thank you! |
I want to do pagination
The text was updated successfully, but these errors were encountered: