Git Product home page Git Product logo

Comments (15)

mathew-kurian avatar mathew-kurian commented on July 27, 2024

Can you provide me with some info of what you already tried? That'll help me get a better start.

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

i use textView in pageCurl, but i don't know with DocumentView.
so, how can i use your view (DocumentView) instead of textView?

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

I don't think we have compatibility at this point. You would need to mess with the code a bit. How do you set the how much text is displayed on each page?

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

first, we get device height, calculating text length for the height (calculating via textview), end, setting the text to the textView

   //setting text to the textView
    tv.setGravity(Gravity.LEFT | Gravity.RIGHT);
    CharSequence text = buffer.getTextbuffer().subSequence(start, end);
    if (text != null && text.length() > 0 && (text.charAt(0) == '\n' || text.charAt(0) == ' ')) {
        text = text.subSequence(1, text.length());
    }
    try {
        tv.setText(text, TextView.BufferType.SPANNABLE);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    tv.draw(canvas);

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

Let me look at it this evening

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

ok, thanks for your time

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

@Jamshidbek Ok. I went through your code and I see that what your doing. Basically, you are telling TextView to draw the contents. The TextJustify code in the latest build relies on something called the DocumentLayout (similar to StaticLayout) to develop and organize the text. You can then do something like documentLayout.draw(canvas) to render text to a canvas of your choice (which you can see here). But this will draw all the text onto the canvas whether or not the content has gone beyond the canvas; which is inefficient for long text like books or things that will be split into "pages". So in the TextJustify build that should be coming out in the next few days, you will be able to do documentLayout.draw(canvas, startY, startY + height) which will be highly efficient because you can specify where to draw the text. So hold on two more days and I will show some sample code here.

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

Ok. Thank you @bluejamesbond.

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

Ok so if you want to render one page to a Bitmap, here is how you do it. It should work for PageCurl as well.

// 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.

jamshid88 avatar jamshid88 commented on July 27, 2024

@bluejamesbond Thank you! Thank you for the great job!
documentLayout doesn't show the text.
i have one question. in initializing,

    // display width and height
    Resources resources = getApplicationContext().getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    bitmapHeight = metrics.heightPixels;
    bitmapWidth = metrics.widthPixels / i;

    // without the method, text doesn't showed
    textview.layout(0, 0, bitmapWidth, bitmapHeight);

without layout method, text doesn't showed in the page curl
how can i apply layout method for documentLayout?

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

@bluejamesbond

I tried it. But it didn't work.

http://stackoverflow.com/a/11260032/1302580

How to possible page curl with textView in android?

it is so simple. Just replace the loadBitmap method in the CurlActivity with the below method,

// load bitmap
private Bitmap loadBitmap(int width, int height, int index)  {
    Bitmap txtBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    String text1 = yourPagesStringArray[index];
    Canvas c = new Canvas(txtBitmap);
    TextView tv = new TextView(getApplicationContext());
    tv.setText(text1);
    tv.setTextColor(0xa00050ff);
    tv.setTextSize(15);
    tv.setLinksClickable(true);
    tv.setLineSpacing(2, 2);
    tv.layout(0, 0, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
    tv.draw(c);

    c.drawBitmap(txtBitmap, 0, 0, null);

    return txtBitmap;
}

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

@Jamshidbek Sorry, I made a mistake in my code.The final code should be something like this:

// Page dimensions
float pageWidth = 400;
float pageHeight = 600;

// Create and setup layout
IDocumentLayout documentLayout = new StringDocumentLayout(context, new TextPaint());
documentLayout.setText("Large text input");
documentLayout.getLayoutParams().setParentWidth(pageWidth);
documentLayout.measure(new IDocumentLayout.ISet<Float>() {
    @Override
    public void set(Float val) {
        // progress for measuring large amounts of text
        Log.d("progress", val.toString());
    }
}, new IDocumentLayout.IGet<Boolean>() {
    @Override
    public Boolean get() {
        // interrupt / cancel the measuring process?
        return false; 
    }
});

// Create bitmap
Bitmap bitmap = Bitmap.createBitmap((int) pageWidth, (int) pageHeight, Bitmap.Config.ARGB_8888);

// If you only want text between 0 and pageHeight
documentLayout.draw(new Canvas(bitmap), 0, pageHeight);

Let me know how this goes.

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

@bluejamesbond
thank you! it's working!!!

from textjustify-android.

mathew-kurian avatar mathew-kurian commented on July 27, 2024

np

from textjustify-android.

jamshid88 avatar jamshid88 commented on July 27, 2024

if i give 0 to drawEndY (startTop) and drawEndY(startBottom), nothing changed. (build: 2.0.4)

// 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.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.