Comments (23)
@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.
from textjustify-android.
How much can I get the page number of rows to display it
2015-01-07 13:47 GMT+08:00 Mathew Kurian [email protected]:
@object1984 https://github.com/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.—
Reply to this email directly or view it on GitHub
#50 (comment)
.
from textjustify-android.
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);
from textjustify-android.
so i should devide large text and i should paginate.
how can i measure text height or how i know filled with text?
from textjustify-android.
Paginating is up to you. Depends on how you use it. If you the provided DocumentView
class which manages the DocumentLayout
then it will do smart caching and automatically draw the content for you. But if you have a large amount of data like a chapter in a book, you can give each DocumentView a chapter of the book and it will manage it for you.
from textjustify-android.
Let me expand. You can give DocumentLayout a very large text. Imagine it is Ypx
tall after documentLayout.measure()
is called. You can then do:
// 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 DocumentLayout#draw(...)
will only draw the text that falls in between the (vertical) offsets you specify.
from textjustify-android.
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
from textjustify-android.
@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.
from textjustify-android.
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
int drawStartY = 0;
int drawEndY = 0;
documentLayout.draw(new Canvas(bitmap), drawStartY, drawEndY);
from textjustify-android.
What do you mean nothing changed?
from textjustify-android.
@bluejamesbond
Oh, it's uninmportant. (if i increase the values nothing changed)
mesaureHeight is normally worked.
Thank you!
from textjustify-android.
@bluejamesbond
now i debugging documentLayout, i set the text, Justify working normally, but last symbol of the text disappeared. sometime, first symbol disappeared on documentLayout
from textjustify-android.
Interesting. Can you provide me with some code to debug.
from textjustify-android.
/**
* 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);
}
from textjustify-android.
Can you provide me the full code?
from textjustify-android.
if curl the page, loadBitmap method will work.
i debugged set the text to documentLayout, but sometimes (not always) first or (both) last symbol disappeared.
/**
* creates bitmap
*
* @param width width of bitmap
* @param height height of bitmap
* @param index index of page
* @return returns ready bitmap
*/
private Bitmap loadBitmap(int width, int height, int index) {
Bitmap b = Bitmap.createBitmap(bitmapWidth, bitmapMinusStatusB, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
// Create and setup layout
documentLayout = new SpannableDocumentLayout(ContentReaderController.this, getTextPaint());
documentLayout.getLayoutParams().setParentWidth(displayWidth);
documentLayout.getLayoutParams().setInsetPaddingLeft(padding);
documentLayout.getLayoutParams().setInsetPaddingRight(padding);
documentLayout.getLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
if (currentPageIndex > curlViewIndex) {
if (mCurlView.isLeft()) {
drawLeftPage(c, getStart(), getEnd());
}
} else {
drawRightPage(c, getStart(), getEnd());
}
return b;
}
/**
* sets text to the text view
*
* @param canvas canvas to be drawn to the text view
*/
private void drawRightPage(Canvas canvas, int start, int end) {
CharSequence text = buffer.getTextBuffer().subSequence(start, end);
if (text.length() > 0 && (text.charAt(0) == '\n' || text.charAt(0) == ' ')) {
text = text.subSequence(1, text.length());
}
setTextAndJustify(text, canvas);
}
from textjustify-android.
@jamshid88 Can you provide getStart
and getEnd
from textjustify-android.
we have large text, if we paginate, save start and end of page index on the text. so they saved numbers.
from textjustify-android.
@jamshid88 I need to see where you invoke documentLayout.draw
and documentLayout.measure
to debug the issue
from textjustify-android.
you can see, documentLayout.draw and documentLayout.measure in setTextAndJustify()
if it's complicated, i can try to give you project
/**
* 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() {
@OverRide
public void onUpdate(Float val) {
Log.d("progress", val.toString());
}
}, new IDocumentLayout.ICancel<Boolean>() {
@Override
public Boolean isCancelled() {
return false;
}
});
documentLayout.draw(canvas);
}
from textjustify-android.
Can you provide me the project?
from textjustify-android.
if text start with the space, 2 nd symbol deleted, if i cut the space(symbol) everythinng ok.
if the text ended with space, last symbol deleted and everything is ok.
Now, everything working.
Thank you for the project and for your job and for your time!
from textjustify-android.
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!
from textjustify-android.
Related Issues (20)
- How to set RTL for Arabic Text
- Extra space in AlertDialog
- max line limit HOT 1
- com.bluejamesbond.text.StringDocumentLayout$PlainDocumentException: Cannot fit word(s) into one line. Font size too large? HOT 2
- is Html text Support ?
- bug java.lang.IllegalArgumentException:
- How to change the text size? HOT 3
- java.lang.IndexOutOfBoundsException HOT 2
- Crash on Android 7.X
- DocumentViews in LinearLayout and EventListeners
- Background Color does not change with Spannables, please help.
- DocumentView has a problem with ExpandableListView
- RTL supprot for documentView_textFormat="plain"
- Broken on API 21 when change portrait to landscape positions
- Hyphenate license
- Image Span test does not work
- Report crash .onMeasure
- How to use android:ellipsize="end" attributes????
- bug: java.lang.IllegalArgumentException: width and height must be > 0
- onClick in Clickablespan is not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textjustify-android.