koreader icon indicating copy to clipboard operation
koreader copied to clipboard

FR? Don't crop when setting semi-automatic cropping.

Open Biep opened this issue 9 months ago • 11 comments

Does your feature request involve difficulty completing a task? Please describe.

Sometimes PDFs have (rareish) marginal notes on both sides. Or odd and even pages are inversely off-centre (e.g. because of a margin gutter). In such cases, setting the proper semi-automatic crop becomes difficult. What we want to do in such a case is move to a page with, say, a left marginal note, and set that side of the crop properly (excluding stuff on the page beyond the note), then move to another page having a right marginal note, and set that side of the crop. (The same may happen vertically, as with footnotes, so in the worst case we may need to visit four pages.)

However, when moving to a page that does not have a left margin note, currently that side of the crop is reset, making such tuning impossible.

Describe the solution you'd like

Simply not autocropping when choosing semi-autowill make the feature much more useable. If needed, long-pressing the button semi-auto could still recrop, in case some mistake was made. Semi-automatic cropping is only used when automatic fails, so one may assume that the auto-cropped start situation is wrong anyway. (Of course some sides may be correct, so starting that way is still useful.)

Biep avatar Mar 21 '25 19:03 Biep

Not sure if you're aware that the page crop areas are already saved separately for odd and even pages (see help text when long-pressing on Page Crop. If this doesn't solve the issue, could you post some screenshots of book pages and which settings you are currently using to crop them?

jonnyl2 avatar Mar 21 '25 20:03 jonnyl2

All right - here is My Masterpiece. I don't want to see the text in the four corners, nor the question marks, but I do want to see the exclamation marks.

Interestingly enough, I don't succeed at all in doing that - it is as if to the crop algorithm the exclamation marks are invisible.

But even if they were visible, it would still be a hit-and-miss issue to get it right, whereas if one crop liner can be set at a time, it would be easier.

A simpler situation, where the exclamation mark and question mark in one margin came on the same page, there would be no trial-and-error needed at all, if crop lines could be set individually.

Of course one can imagine the same happening at the top and bottom.

Biep avatar Mar 28 '25 21:03 Biep

So like this?

https://github.com/user-attachments/assets/a5e744e5-734a-4167-942b-6068cb98f2e9

jonnyl2 avatar Mar 28 '25 22:03 jonnyl2

Yes, that is the behaviour I want. (For some reason I can't get the KOReader cropper to see the exclamation marks at all, but that is another issue.) What I'd like is to be able to set one crop line on one page, where one can see the relevant information for that line, and then go to another page to set another one of the four crop lines. Maybe an example where one page has the left question and exclamation marks, and another the right ones, would have been clearer. Then it would be obvious that only, say, only page one can inform about the position of the left crop line, and page three about the position of the right crop line. Other pages might give the information needed to set the top and bottom crop lines.

My Masterpiece 2nd edition

Biep avatar Mar 28 '25 22:03 Biep

This also works for me, at least on the emulator:

https://github.com/user-attachments/assets/e23e78a8-fa2e-4b2b-bcb2-44667fb9b159

jonnyl2 avatar Mar 28 '25 23:03 jonnyl2

Ah, yes - but you set the right crop line "blindly" - without seeing the relevant data to know where the line should go. I provided a rather wide margin, but imagine a tiny gutter between the exclamation and question marks. And not symmetric, so that the left line does not inform where the right line should go (and, of course, vice versa).

My Masterpiece, 3rd, improved, edition

Sorry for the stepwise approach to the correct example.. I hope this is it.

Biep avatar Mar 29 '25 00:03 Biep

Still working for me, if I set the crop area separately on the 3rd page. Of course I don't know how that would pan out on longer documents. But I'm still not sure what you're suggesting to change to be honest.

https://github.com/user-attachments/assets/e5ab2cd1-6fa2-4ef7-bf9e-af299a3aa3b6

jonnyl2 avatar Mar 29 '25 10:03 jonnyl2

Wait - maybe it is just a visual effect. When I go to the third page, I see (in your film too) the left crop line up with the text - not the place where it ought to be. So I have always assumed it had lost the position where I had set it on page 1.

Right now I cannot check whether this actually is the case on my system, as for some reason the cropper does not see the exclamation mark. It does lose knowledge of the bottom crop line, as when I set the left and top margin at the last (incomplete) page, when I go back to an earlier page it cuts off the bottom. I see you pull back the bottom crop line (blindly again), so it seems you had the same issue.

In any case, showing the crop line where the system believes it to be would be a good idea. The current view gives the (correct or incorrect) impression that the crop lines as set before have been forgotten.

Biep avatar Mar 29 '25 18:03 Biep

Anyway, my request is this:

  • Remember the crop lines as previously set when again tapping semi-auto.
  • Show these crop lines, so there is visual confirmation that the system indeed remembers those crop lines.
  • Any crop line not actively replaced in semi-auto remains where it was before semi-auto was opened.

Biep avatar Mar 29 '25 18:03 Biep

Here is a document that currently is hard to crop properly. I want no page numbers, but all the main text.

Analysis and Efficient Implementation of F - Peter Sestoft.pdf

Biep avatar May 05 '25 20:05 Biep

What are you having trouble with? It works perfectly for me using semi-auto crop and zoom to contents.

jonnyl2 avatar May 05 '25 20:05 jonnyl2

We are in the midst of moving from Sweden to the Netherlands - but once we are settled again I hope to describe the problem in some detail. One issue pops up when trying to avoid the page numbers at the bottom of the first page of each chapter - when opening the sem-auto crop to set the bottom line, the top line has come down because the text on those first pages starts lower than on other pages. I want that line to remain where I set it, and not move all by itself.

Biep avatar May 07 '25 20:05 Biep

You need to set the crop area on a page filled with text from top to bottom. The semi-crop mode only crops more when needed, but never less. That's why it doesn't work if you set the area on a page with larger top/bottom margins.

Good luck on your move!

jonnyl2 avatar May 07 '25 21:05 jonnyl2

Yes - but those bottom page numbers only show up on the first page of a chapter, which always has a larger top margin than other pages. A document may well have no single page that is filled fully at all four sides. And even if there were such an "ideal page" allowing me to set all four crop lines at once - having to hunt for that page would be a pain. If only the top crop line would simply stay where I had placed it, there would be no issue. I don't understand why it moves at all in the first place, actively working to make setting the crop area harder.

Biep avatar May 07 '25 21:05 Biep

I don't understand why it moves at all in the first place, actively working to make setting the crop area harder.

Not super familiar with PDF, but from my experience, this happens with "semi auto": you define some outer rectangle (leaving page decorations outside), and it crops out the blank inside that rectangle. If you choose "manual", your rectangle stays as-is.

poire-z avatar May 07 '25 21:05 poire-z

If only the top crop line would simply stay where I had placed it, there would be no issue.

I see, so you would like something like a mixed semi-auto/manual crop, where each of the 4 margins can be designated to be either semi-auto (where it would crop further when applicable), or manual (and always stay put on each page). Interesting idea. Not sure how feasible it would be.

jonnyl2 avatar May 07 '25 21:05 jonnyl2

@poire-z: Yes - but then (I think, I should retry) it doesn't crop at all, even when there is lots of white space on some side. I want it to crop, but ignore anything outside a given rectangle - but the problem is specifying that rectangle.

I may need up to eight different placements (four sides x left/right page) to get it correct, which is fine. But if the lines I already set start moving spontaneously when I set the next one, I never get done.

Biep avatar May 07 '25 21:05 Biep

If only the top crop line would simply stay where I had placed it, there would be no issue.

I see, so you would like something like a mixed semi-auto/manual crop, where each of the 4 margins can be designed to be either semi-auto (where it would crop further when applicable), or manual (and always stay put on each page). Interesting idea. Not sure how feasible it would be.

No, nothing as advanced as that. (Though I can imagine people wanting that too..) All I want is being able to set each crop line while the others stay where they are. When actually reading the book, they should steer cropping the way they currently do; it is only the behaviour while setting the lines that I want simplified:

  • Crop when reading
  • Don't crop when setting crop lines. (Except maybe the very first time, to get decent defaults - but a better approach would be to have a button or gesture for full cropping within the existing lines on the current page. But let's keep that out of the discussion for now, until I have managed to get my issue across, so: don't crop when setting crop lines.)

Biep avatar May 07 '25 21:05 Biep

I realise my terminology may be confusing. Let me distinguish:

  1. The "crop margin" - a rectangle outside of which nothing is shown, and inside which cropping may take place. Auto-cropping assumes a crop margin of zero, i.e. the rectangle coincides with the page rim. Semi-auto cropping allows one to place a crop margin anywhere on the page; typically, one would place it such that header and footer text fall outside it, but page content inside it.
  2. The "cut frame" - the rectangle indicating precisely what will be shown on the e-reader screen. With (semi-)autocropping, this is the smallest rectangle such that there is no content matter in the area between it and the crop margin. With manual cropping, the cut frame coincides with the crop margin.

Now those are two very different concepts, and they seem to get mixed up. When (semi-)auto cropping, one expects the cut frame to move "spontaneously" - but one never expects the crop margin to move. Yet, when setting a crop margin in stages (go to page X, set the crop margin top line, go to page Y, set the crop margin bottom line, ..), the crop margin does spontaneously move, frustrating the attempt to set it precisely.

@jonnyl2, in your little film of setting the crop margin, around second 20 you open the semi-auto again, and the bottom line of the margin has moved way up. You then move it down again, felicitously getting it right - but imagine that it had to be at a very specific height, which would be unlikely to be settable by guessing! (Also - you use a mouse, it seems, whereas e-reader users typically have to make do with fat fingers, so that any precise setting is hard work already.) That bottom line should have stayed down where it was, as it is a crop margin line, and not a cut frame line. The latter may move spontaneously to hug the page content, but the former should remain stolid and immovable.

Biep avatar May 08 '25 15:05 Biep

@Biep Now that you mention it, this has been bothering me too, that the crop selection area always readjusts itself back to the auto-area. ~~Please try with this change:~~

Edit: Nevermind, this will just duplicate the manual crop.

~~(Or just edit the function in the original file, commenting out the 3 lines in the elseif-block:)~~

function KoptInterface:getPageBBox(doc, pageno)
    if doc.configurable.text_wrap ~= 1 and doc.configurable.trim_page == 1 then
        -- auto bbox finding
        return self:getAutoBBox(doc, pageno)
    -- elseif doc.configurable.text_wrap ~= 1 and doc.configurable.trim_page == 2 then
        -- -- semi-auto bbox finding
        -- return self:getSemiAutoBBox(doc, pageno)
    else
        -- get saved manual bbox
        return Document.getPageBBox(doc, pageno)
    end
end

jonnyl2 avatar May 11 '25 18:05 jonnyl2

this has been bothering me too, that the crop selection area always readjusts itself back to the auto-area.

@jonnyl2 Funny, I was about to comment the same :D I tried and edited the function, but now it doesn't work for me - it doesn't crop at all anymore. Also the first time I open semi-auto, I can edit the crop selection. The second time, I can't edit the right side (the left side of the crop selection jumps to the right).

noxhirsch avatar May 11 '25 18:05 noxhirsch

@noxhirsch It is working fine on the emulator and on my Kobo, not sure what's causing your issues.

jonnyl2 avatar May 11 '25 19:05 jonnyl2

@jonnyl2 I checked again: Somehow I had managed to reenable an old unused patch which confliced with the change (sorry that I didn't check that first). I disabled that and now the crop selection is behaving as expected (and exactly as I wish it would work). But now the book just gets cropped to my crop selection (like manual crop). Does that work for you too?

noxhirsch avatar May 11 '25 19:05 noxhirsch

You're right; I thought it was still doing the semi-auto crop in the Reader view (I could have sworn it did, hah). I'll take a look again.

jonnyl2 avatar May 11 '25 19:05 jonnyl2

Now that you mention it, this has been bothering me too, that the crop selection area always readjusts itself back to the auto-area.

Yes! That is the point I had been - ineffectually - trying to make from the start! Sorry for having been so obtuse - and thank you for having been so patient with me.

Biep avatar May 12 '25 19:05 Biep

And now that I am fairly convinced that we are talking about the same thing: Auto-cropping during crop area selection (the "readjusting" you mention) is bothering, but having an option to auto-crop that way - during crop area selection - can be quite helpful. So, given that the code to readjust exists already, having, e.g., a gesture to trigger it would be a good idea in my mind.

Biep avatar May 12 '25 19:05 Biep

I think the best solution would be no automatic crop in the semi-crop selection "dialog", but have a button in the bottom row for that: [ Cancel ] [ Auto crop ] [ Apply crop ] or [ Cancel ] [ Auto select ] [ Apply crop ]

noxhirsch avatar May 12 '25 20:05 noxhirsch

In that case just make sure that leaving the Semi-auto crop "dialog" does not change the current page. That sometimes happens, and could lead to unexpected consequences of crop application.

Biep avatar May 12 '25 20:05 Biep