diff --git a/src/DisplayModel.cpp b/src/DisplayModel.cpp index e82439746334..8fd96721f708 100644 --- a/src/DisplayModel.cpp +++ b/src/DisplayModel.cpp @@ -74,19 +74,6 @@ static int ColumnsFromDisplayMode(DisplayMode displayMode) { return 1; } -int NormalizeRotation(int rotation) { - CrashIf((rotation % 90) != 0); - rotation = rotation % 360; - if (rotation < 0) { - rotation += 360; - } - if (rotation < 0 || rotation >= 360 || (rotation % 90) != 0) { - CrashIf(true); - return 0; - } - return rotation; -} - ScrollState::ScrollState(int page, double x, double y) : page(page), x(x), y(y) { } diff --git a/src/DisplayModel.h b/src/DisplayModel.h index 002b4a380d48..06dde4f11a5f 100644 --- a/src/DisplayModel.h +++ b/src/DisplayModel.h @@ -246,5 +246,3 @@ struct DisplayModel : public Controller { resp. number of Back history entries */ size_t navHistoryIdx{0}; }; - -int NormalizeRotation(int rotation); diff --git a/src/EngineDjVu.cpp b/src/EngineDjVu.cpp index d6b5d234acb4..783ef9c0fd0d 100644 --- a/src/EngineDjVu.cpp +++ b/src/EngineDjVu.cpp @@ -553,7 +553,7 @@ RenderedBitmap* EngineDjVu::RenderPage(RenderPageArgs& args) { auto pageRect = args.pageRect; auto zoom = args.zoom; auto pageNo = args.pageNo; - auto rotation = args.rotation; + auto rotation = NormalizeRotation(args.rotation); RectF pageRc = pageRect ? *pageRect : PageMediabox(pageNo); Rect screen = Transform(pageRc, pageNo, zoom, rotation).Round(); Rect full = Transform(PageMediabox(pageNo), pageNo, zoom, rotation).Round(); @@ -563,9 +563,6 @@ RenderedBitmap* EngineDjVu::RenderPage(RenderPageArgs& args) { if (!page) { return nullptr; } - int rotation4 = (((-rotation / 90) % 4) + 4) % 4; - ddjvu_page_set_rotation(page, (ddjvu_page_rotation_t)rotation4); - while (!ddjvu_page_decoding_done(page)) { gDjVuContext->SpinMessageLoop(); } @@ -573,6 +570,28 @@ RenderedBitmap* EngineDjVu::RenderPage(RenderPageArgs& args) { return nullptr; } + ddjvu_page_rotation_t rot = DDJVU_ROTATE_0; + switch (rotation) { + case 0: + rot = DDJVU_ROTATE_0; + break; + // for whatever reason, 90 and 270 are reverased compared to what I expect + // maybe I'm doing other parts of the code wrong + case 90: + rot = DDJVU_ROTATE_270; + break; + case 180: + rot = DDJVU_ROTATE_180; + break; + case 270: + rot = DDJVU_ROTATE_90; + break; + default: + CrashIf("invalid rotation"); + break; + } + ddjvu_page_set_rotation(page, rot); + bool isBitonal = DDJVU_PAGETYPE_BITONAL == ddjvu_page_get_type(page); ddjvu_format_style_t style = isBitonal ? DDJVU_FORMAT_GREY8 : DDJVU_FORMAT_BGR24; ddjvu_format_t* fmt = ddjvu_format_create(style, 0, nullptr); @@ -618,7 +637,6 @@ RectF EngineDjVu::PageContentBox(int pageNo, [[maybe_unused]] RenderTarget targe if (!page) { return pageRc; } - ddjvu_page_set_rotation(page, DDJVU_ROTATE_0); while (!ddjvu_page_decoding_done(page)) { gDjVuContext->SpinMessageLoop(); @@ -626,6 +644,7 @@ RectF EngineDjVu::PageContentBox(int pageNo, [[maybe_unused]] RenderTarget targe if (ddjvu_page_decoding_error(page)) { return pageRc; } + ddjvu_page_set_rotation(page, DDJVU_ROTATE_0); // render the page in 8-bit grayscale up to 250x250 px in size ddjvu_format_t* fmt = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, nullptr); @@ -710,10 +729,8 @@ PointF EngineDjVu::TransformPoint(PointF pt, int pageNo, float zoom, int rotatio zoom = 1.0f / zoom; } - rotation = rotation % 360; - while (rotation < 0) { - rotation += 360; - } + rotation = NormalizeRotation(rotation); + PointF res = pt; // for rotation == 0 if (90 == rotation) { res = PointF(page.dy - pt.y, pt.x); diff --git a/src/log.txt b/src/log.txt index 1326bb236c5c..29762b178d17 100644 --- a/src/log.txt +++ b/src/log.txt @@ -1,5 +1,30 @@ A daily log of changes and commentary. An experiment of sorts. +======= +2021-07-06 Tue + +don't ask to save unsaved annotations in stress testing + +sign when building locally + +make 3.3 release + +update mupdf + +update harfbuzz + +update lcms2 + +update openjpeg + +simplify cmd-line arg parsing + +rename CClassFactory => FilterClassFactory / PreviewClassFactory + +fix DjVu rotation (fixes #1593) +must process the file before setting rotation +https://github.com/sumatrapdfreader/sumatrapdf/issues/1593 + 2021-06-29 Tue simplify GetPaperFormat() @@ -53,7 +78,7 @@ in annotations editor, add explicit button for saving to a new PDF instead of ct make default annotation color yellow (0xffffff00) so it matches value in gColorsValues -add context menu Select annotation when cursor over annotation and edit annotation window is visible (replaces Edit annotations menu) (for #1992) +add context menu�Select annotation�when cursor over annotation and edit annotation window is visible (replaces�Edit annotations�menu) (for #1992) https://github.com/sumatrapdfreader/sumatrapdf/issues/1992 fix DefaultAppearanceTextColor() (for #1974) diff --git a/src/utils/FileUtil.cpp b/src/utils/FileUtil.cpp index 9fe5e4cf1dce..9e83d0d338cf 100644 --- a/src/utils/FileUtil.cpp +++ b/src/utils/FileUtil.cpp @@ -499,8 +499,8 @@ std::span ReadFileWithAllocator(const char* filePath, Allocator* allocator) if (nRead != size) { int err = ferror(fp); int isEof = feof(fp); - logf("ReadFileWithAllocator: fread() failed, path: '%s', size: %d, nRead: %d, err: %d, isEof: %d\n", filePath, (int)size, (int)nRead, - err, isEof); + logf("ReadFileWithAllocator: fread() failed, path: '%s', size: %d, nRead: %d, err: %d, isEof: %d\n", filePath, + (int)size, (int)nRead, err, isEof); // we should either get eof or err // either way shouldn't happen because we're reading the exact size of file // I've seen this in crash reports so maybe the files are over-written diff --git a/src/utils/GeomUtil.cpp b/src/utils/GeomUtil.cpp index e9dad4a5882b..52c3c686f727 100644 --- a/src/utils/GeomUtil.cpp +++ b/src/utils/GeomUtil.cpp @@ -444,3 +444,17 @@ Gdiplus::Rect ToGdipRect(const RectF r) { Gdiplus::RectF ToGdipRectF(const RectF r) { return Gdiplus::RectF(r.x, r.y, r.dx, r.dy); } + +int NormalizeRotation(int rotation) { + while (rotation < 0) { + rotation += 360; + } + while (rotation >= 360) { + rotation -= 360; + } + if ((rotation % 90) != 0) { + CrashIf(true); + return 0; + } + return rotation; +} \ No newline at end of file diff --git a/src/utils/GeomUtil.h b/src/utils/GeomUtil.h index fa533aa8b044..dbc6ad96c17c 100644 --- a/src/utils/GeomUtil.h +++ b/src/utils/GeomUtil.h @@ -144,3 +144,5 @@ RECT ToRECT(const RectF r); Rect ToRect(const RectF r); Gdiplus::Rect ToGdipRect(const RectF r); Gdiplus::RectF ToGdipRectF(const RectF r); + +int NormalizeRotation(int rotation);