Bug 4930 - PDF Reader doesn't use optimal screen width in fit width mode.
: PDF Reader doesn't use optimal screen width in fit width mode.
Status: RESOLVED WONTFIX
Product: Utilities
PDF reader
: 5.0/(1.2009.41-10)
: All Linux
: Low enhancement with 5 votes (vote)
: ---
Assigned To: unassigned
: pdf-reader-bugs
:
: community-diablo, patch
:
:
  Show dependency tree
 
Reported: 2009-08-17 01:28 UTC by Hauweele Pierre
Modified: 2012-03-24 11:44 UTC (History)
4 users (show)

See Also:


Attachments
The trivial patch. (701 bytes, patch)
2009-08-17 01:30 UTC, Hauweele Pierre
Details
screenshot of test page at "fit width" zoom before applying the patch (59.18 KB, image/png)
2009-08-17 02:13 UTC, Lucas Maneos
Details
and after (56.85 KB, image/png)
2009-08-17 02:14 UTC, Lucas Maneos
Details
combined fit-width & scrollbar patch (2.00 KB, patch)
2009-08-17 04:59 UTC, Lucas Maneos
Details
combined fit_width & get_custom_zoom_level patch (1.54 KB, patch)
2009-08-17 06:38 UTC, Hauweele Pierre
Details
dpi rounding consequence (79.14 KB, image/png)
2009-08-18 23:40 UTC, Hauweele Pierre
Details
attachment 1326 + correct VIEWPORT_WIDTH/VIEWPORT_HEIGHT + floating point DPI calculations (5.14 KB, patch)
2009-08-19 05:29 UTC, Lucas Maneos
Details
Incremental corrections to attachment 1330 (2.77 KB, patch)
2009-08-19 15:37 UTC, Hauweele Pierre
Details
combined previous patchs with corrections (6.97 KB, patch)
2009-08-20 02:06 UTC, Hauweele Pierre
Details


Note

You need to log in before you can comment on or make changes to this bug.


Description Hauweele Pierre (reporter) 2009-08-17 01:28:42 UTC
This can be well seen when changing the paper color to something different than
white.
The problem comes from some wrong logic code (if i'm not wrong myself) ; there
is a strange check for scrollbar in fit width mode that always (in fact, only
when screen_height < screen_width, that is, for me, always true) assumes a 40
pixels scrollbar although the scrollbar presence was already handled a few
lines before.
I'll attach a trivial patch against 1.5.35.
Comment 1 Hauweele Pierre (reporter) 2009-08-17 01:30:36 UTC
Created an attachment (id=1322) [details]
The trivial patch.
Comment 2 Lucas Maneos 2009-08-17 02:13:39 UTC
Created an attachment (id=1323) [details]
screenshot of test page at "fit width" zoom before applying the patch
Comment 3 Lucas Maneos 2009-08-17 02:14:02 UTC
Created an attachment (id=1324) [details]
and after
Comment 4 Lucas Maneos 2009-08-17 02:17:06 UTC
Confirming, and many thanks for the patch!  This may also go some way to
satisfying bug 761.

The only issue is that osso-pdf-viewer now displays a (useless) horizontal
scrollbar when at "fit width" zoom (see attached screenshots).  Not this
patch's fault though.
Comment 5 Hauweele Pierre (reporter) 2009-08-17 04:27:16 UTC
> The only issue is that osso-pdf-viewer now displays a (useless) horizontal
> scrollbar when at "fit width" zoom (see attached screenshots).  Not this
> patch's fault though.
> 

Thanks for screenshots and pointing this out. I'll see if I can fix it. The
patch might finally not be so trivial.
Comment 6 Lucas Maneos 2009-08-17 04:59:27 UTC
Created an attachment (id=1325) [details]
combined fit-width & scrollbar patch

The scrollbar problem seems to be calc_size_dpi() subtracting SCROLLBAR_SIZE
from width/height.  I don't think that's needed.

The scrollbar calculation worked before your patch only because
get_custom_zoom_level() was subtracting an even larger value.

The attached patch seems to work fine, but verification welcome (it is rather
late here...)
Comment 7 Hauweele Pierre (reporter) 2009-08-17 06:38:28 UTC
Created an attachment (id=1326) [details]
combined fit_width & get_custom_zoom_level patch

> The scrollbar problem seems to be calc_size_dpi() subtracting SCROLLBAR_SIZE
> from width/height.  I don't think that's needed.
No, it IS needed. With your patch there will be sometimes where a needed
scrollbar will not be showed.

> The scrollbar calculation worked before your patch only because
> get_custom_zoom_level() was subtracting an even larger value.
Yes, indeed.

The real problem seems to come from that (in get_custom_zoom_level):
    double screen_width =
        (double) priv->app_ui_data->scrolled_window->allocation.width;
    double screen_height =
        (double) priv->app_ui_data->scrolled_window->allocation.height;
In my tests, [...]allocation.width is 696 wich is bigger than
VIEWPORT_WIDTH(=672).
Then the SCROLLBAR_SIZE's got removed from that, giving 674 and due to the int
rounding of dpi, it works (the layout is then 671).
I don't know what exactly that scrolled_window->allocation.width represents nor
why does it has that value. But we don't really need it, indeed screen_width in
get_custom_level represents the available drawing space. So it is either
FULLSCREEN_WIDTH or VIEWPORT_WIDTH depending on the case we're in fullscreen
mode or not.
Maybe the use of scrolled_window->allocation.width was thought a shortcut to
avoid having to check the PDF_FLAGS_FULLSCREEN flag.

The attached patch should be okay.
Comment 8 Lucas Maneos 2009-08-17 10:47:17 UTC
(From update of attachment 1325 [details])
Thanks again :-)

One problem now is that it still wastes horizontal pixels (though fewer than
the original) when in windowed mode.  I think it's because the VIEWPORT_WIDTH
value already has the scrollbar width subtracted.
Comment 9 Hauweele Pierre (reporter) 2009-08-17 14:52:24 UTC
To my calculations, the only wasted pixels are coming from the rounding of the
calculated dpi value in the (guint) cast. But I didn't verify that on the new
patch, I don't have much time for that today, it will be for tomorrow/tonight.
This should be fixed if we modify the code to use (double) dpi everywhere or
only on the path of dpi's values used by the custom_zoom_level mechanism.
>the original) when in windowed mode.  I think it's because the VIEWPORT_WIDTH
>value already has the scrollbar width subtracted.
Will have to verify that too, but I think it is correct since, if I remember
well, after the initial trivial patch the layout width used was 674, so 2
pixels higher than VIEWPORT_WIDTH (explaining the scrollbar) and it seemed to
use full viewport width.
Comment 10 Hauweele Pierre (reporter) 2009-08-18 18:56:22 UTC
> Will have to verify that too, but I think it is correct since, if I remember
> well, after the initial trivial patch the layout width used was 674, so 2
> pixels higher than VIEWPORT_WIDTH (explaining the scrollbar) and it seemed to
> use full viewport width.
Hum, I'm sorry, I was totally wrong and you were right Lucas. Indeed it shows
in fact that, yes, the VIEWPORT_WIDTH value already has the scrollbar width
substracted. Since the layout size would have to be VIEWPORT_WIDTH -
SCROLLBAL_SIZE.
I have doubts about the real VIEWPORT_WIDTH, is it 694(=672+22) or
676(=priv->app_ui_data->scrolled_window->allocation.width) ?
So 2 pixels would have to be substracted somewhere ?
Comment 11 Lucas Maneos 2009-08-18 23:05:34 UTC
(In reply to comment #10)
> I have doubts about the real VIEWPORT_WIDTH, is it 694(=672+22) or
> 676(=priv->app_ui_data->scrolled_window->allocation.width) ?
> So 2 pixels would have to be substracted somewhere ?

It should be 696 pixels according to
<http://maemo.org/development/training/maemo_technology_overview_content/plain_html/node5/#SECTION00532000000000000000>.
 I don't know where those 2 extra pixels go :-(
Comment 12 Hauweele Pierre (reporter) 2009-08-18 23:40:53 UTC
Created an attachment (id=1329) [details]
dpi rounding consequence

> It should be 696 pixels according to [...]
Right, I have measured the viewport size on screenshots, with the scrollbar it
is 674 and without it, it is
696(=priv->app_ui_data->scrolled_window->allocation.width) -- excuse the typos
my previous post.
So Lucas was definitely right about the fact that SCROLLBAR_SIZE was already
substracted from VIEWPORT_WIDTH.
Updating the VIEWPORT_WIDTH value to the correct one works, but there is still
the problem of the rounding of the dpi value. That value is sometimes used as
double, and sometimes used as integer.
The rendering actually use the dpi value as double, the width of the displayed
document when using fit width (with vertical scrollbar) is indeed 674 as
expected. But at some places, the dpi value is used as integer, e.g the width
value in calc_size_dpi. That width value is then 671 and that causes a little
problem in the centering of the document. Indeed, the layout's width is viewed
as being 671 in a 674 viewport (although it really is 674) so it is centered
one pixel right and then you loose 1 pixel at right of the document.
Can we change the casts to double everywhere foo the dpi value, would'nt it
cause any other bug ?
And also, since SCROLLBAR_SIZE was already substracted from the VIEWPORT_WIDTH
value, isn't there any code that makes the assumption that it is done so ? Does
someone knows that or will we have to check the code everywhere that value is
used ?
Comment 13 Lucas Maneos 2009-08-19 05:29:07 UTC
Created an attachment (id=1330) [details]
attachment 1326 [details] + correct VIEWPORT_WIDTH/VIEWPORT_HEIGHT + floating point DPI
calculations

For reference:

- According to the documentation the normal view application area with a single
toolbar should be 696 x 360.

- src/constant.h defines:
#define SCROLLBAR_SIZE       22
#define VIEWPORT_WIDTH       672
#define VIEWPORT_HEIGHT      362

SCROLLBAR_SIZE seems correct (measured with gimp it's 20 pixels wide plus one
pixel padding on either side).

VIEWPORT_WIDTH has (SCROLLBAR_SIZE + 2) pixels subtracted relative to the
documented dimensions, while VIEWPORT_HEIGHT has 2 pixels *added*.  Fun...

(In reply to comment #12)
> Updating the VIEWPORT_WIDTH value to the correct one works, but there is still
> the problem of the rounding of the dpi value. That value is sometimes used as
> double, and sometimes used as integer.
> [...]
> But at some places, the dpi value is used as integer, e.g the width
> value in calc_size_dpi. That width value is then 671 and that causes a little
> problem in the centering of the document.

Indeed, good catch!  It also causes a few lines at the bottom to be off-screen
in fit-width or fit-page zoom on some documents.

> Can we change the casts to double everywhere foo the dpi value, would'nt it
> cause any other bug ?

Let's find out :-) This change touches several places, and I'm not sure I got
all of them but it compiles without (additional) warnings and it seems to work.
 Review welcome of course.

> And also, since SCROLLBAR_SIZE was already substracted from the VIEWPORT_WIDTH
> value, isn't there any code that makes the assumption that it is done so ?

It doesn't seem so, in fact calc_size_dpi() assumes the opposite and subtracts
another SCROLLBAR_SIZE pixels if it thinks it's necessary.

> someone knows that or will we have to check the code everywhere that value is
> used ?

Thankfully these #defines are not used outside of pdfviewer.cc so it should be
safe.
Comment 14 Hauweele Pierre (reporter) 2009-08-19 15:37:32 UTC
Created an attachment (id=1331) [details]
Incremental corrections to attachment 1330 [details]

(In reply to comment #13)
Thanks for that patch.

> - According to the documentation the normal view application area with a single
> toolbar should be 696 x 360.
It is strange that app_ui_data->scrolled_window->allocation.height is 362. And
in fact measuring the viewport height in gimp gives 362 too. So I would trust
gimp and not the documentation about that viewport dimensions :-D
So here is my incremental patch to attachment 1330 [details].

That may sound somewhat out of topic (it would rather go with some code
cleaning) but couldn't we use floats instead of doubles for dpi ?
We don't need a high precision on dpi since the layout dimensions are of 1
pixel per SCREEN_DPI/page_dimension dpi, that is 72/612 in our common case for
width. That is 1 pixel per ~0.11764 dpi. So we could save some bits without any
cost (i think).
Comment 15 Lucas Maneos 2009-08-20 00:54:23 UTC
(In reply to comment #14)
> It is strange that app_ui_data->scrolled_window->allocation.height is 362. And
> in fact measuring the viewport height in gimp gives 362 too. So I would trust
> gimp and not the documentation about that viewport dimensions :-D

You are right, and 362 does give 2 extra pixels at "fit page" zoom.  I guess
there's no point filing a bug against Diablo docs anymore, but hopefully this
one should now contain enough google fodder for others who are wondering to
find.

> So here is my incremental patch to attachment 1330 [details].

You missed VIEWPORT_HEIGHT ;-) (VIEWPORT_BUFFER_HEIGHT is dead code at the
moment, I just changed it to be consistent).

> That may sound somewhat out of topic (it would rather go with some code
> cleaning) but couldn't we use floats instead of doubles for dpi ?

Sure, if you feel like it, although the rest of the code uses doubles (with one
trivial exception) so it hardly seems worth the effort. But maybe
(stylistically speaking, it doesn't make any difference otherwise) some should
be gdoubles/gfloats instead?
Comment 16 Hauweele Pierre (reporter) 2009-08-20 02:06:15 UTC
Created an attachment (id=1335) [details]
combined previous patchs with corrections

Here is the full patch against 1.5.35
(In reply to comment #15)
> You missed VIEWPORT_HEIGHT ;-) (VIEWPORT_BUFFER_HEIGHT is dead code at the
Oops. Thanks.
There was another equality test on newly double instead of int in
ui/interface.c.
I have removed the test for the PDF_FLAGS_FULLSCREEN that I have introduced
before, since the initial code using
app_ui_data->scrolled_window->allocation.width (and height) is finally correct.

Thanks again for your help Lucas.
I hope there's no more missing corrections to make against those changes.
Comment 17 Lucas Maneos 2009-08-20 12:58:18 UTC
(From update of attachment 1330 [details])
(In reply to comment #16)
> Here is the full patch against 1.5.35

Looks fine to me.

> Thanks again for your help Lucas.

No, thank you :-)
Comment 18 Andre Klapper maemo.org 2009-09-28 20:11:17 UTC
As Diablo/Maemo4 will not receive any such fixes anymore, it would be more than
welcome if you could update the patch for the Maemo5 codebase once this part is
public. There should not have been many changes in this code (probably none).
Thanks in advance!
Comment 19 Lucas Maneos 2009-10-12 15:15:36 UTC
(In reply to comment #18)
> As Diablo/Maemo4 will not receive any such fixes anymore, it would be more than
> welcome if you could update the patch for the Maemo5 codebase once this part is
> public. There should not have been many changes in this code (probably none).

Source or binaries aren't available yet (at least not in
<http://repository.maemo.org/pool/maemo5.0/free/o/> or anywhere apt-get can
find them), but based on the on-device pre-installed binary there's at least
one significant change: "fit width" zoom has been removed from the Fremantle
version.  Otherwise the app hasn't changed much so it shouldn't be too hard to
add it back.
Comment 20 Hauweele Pierre (reporter) 2009-10-12 16:21:42 UTC
> Source or binaries aren't available yet (at least not in
> <http://repository.maemo.org/pool/maemo5.0/free/o/> or anywhere apt-get can
> find them),
I'm patiently waiting for them.
Comment 21 Andre Klapper maemo.org 2009-10-13 14:13:18 UTC
Zoom is only available from the toolbar, so I wonder how to quickly go to Fit
width mode? :-/

Currently this becomes enhancement because Fid width is simply not available
and not planned. Which is a pity of course.
Comment 22 Lucas Maneos 2009-10-22 07:57:51 UTC
Marking patches of interest to Diablo (Maemo4) community updates, please excuse
the noise.
Comment 23 Andre Klapper maemo.org 2012-03-24 11:44:12 UTC
The Maemo 5 User Interface and Maemo 5 platform components (e.g. libraries)
used for the N900 are considered stable by Nokia and it seems that there are no
plans for official updates currently, hence nobody plans to work on this
enhancement/wishlist request. 
(And in case you feel like discussing this situation: Nokia Customer Care or
http://talk.maemo.org would be the place to do so as you will not reach Nokia
officials in this community bugtracker - though all of this is really no news.)

Reflecting this status by setting RESOLVED WONTFIX for this
enhancement/wishlist request (see
https://bugs.maemo.org/page.cgi?id=fields.html#status for status explanations).

There is a small chance for issues in those Maemo components that are open
source: Contributed patches could be included and made available in the Maemo 5
Community CSSU updates. 
The Maemo CSSU project is run by a small team of volunteers; see
http://wiki.maemo.org/CSSU for more information.
So in case that you can provide a patch that fixes the reported problem, please
feel encouraged to file a request under
https://bugs.maemo.org/enter_bug.cgi?product=Maemo%205%20Community%20SSU .
Please note: The Maemo CSSU project is not related in any way to Nokia.


( Tag for mass-deleting bugmail: [cleanup20120324] )