-
-
Notifications
You must be signed in to change notification settings - Fork 30
Background and previous improvements #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fa86295
clean up code
Ethran bc718f7
Refactor background rendering logic to improve modularity and consoli…
Ethran 77dae0a
Refactor page rendering and thumbnail generation logic
Ethran 1eec939
remove waitForEpdRefresh
Ethran caff133
rename to PreviewBitmapStore.kt
Ethran 2e500f5
Refactor page preview and thumbnail persistence logic to use the WEBP…
Ethran 76a0814
Adjust preview quality and clean up logging in PreviewBitmapStore
Ethran 1462c4d
rename image decoding utility.
Ethran 1c113da
Refactor device information gathering and optimize preview/thumbnail …
Ethran 0508ff2
Refactor `ImportEngine` to return result objects and integrate automa…
Ethran a41b6a6
apply copilot suggestions
Ethran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,9 +10,13 @@ import android.graphics.Paint | |||||
| import android.graphics.Rect | ||||||
| import android.graphics.RectF | ||||||
| import androidx.compose.ui.geometry.Offset | ||||||
| import androidx.compose.ui.graphics.ImageBitmap | ||||||
| import androidx.compose.ui.graphics.asAndroidBitmap | ||||||
| import androidx.compose.ui.res.imageResource | ||||||
| import androidx.compose.ui.unit.IntOffset | ||||||
| import androidx.core.graphics.createBitmap | ||||||
| import androidx.core.graphics.toRect | ||||||
| import com.ethran.notable.R | ||||||
| import com.ethran.notable.SCREEN_HEIGHT | ||||||
| import com.ethran.notable.SCREEN_WIDTH | ||||||
| import com.ethran.notable.data.CachedBackground | ||||||
|
|
@@ -29,7 +33,7 @@ import com.ethran.notable.editor.drawing.drawBg | |||||
| import com.ethran.notable.editor.drawing.drawOnCanvasFromPage | ||||||
| import com.ethran.notable.editor.utils.div | ||||||
| import com.ethran.notable.editor.utils.divideStrokesFromCut | ||||||
| import com.ethran.notable.editor.utils.loadPersistBitmap | ||||||
| import com.ethran.notable.editor.utils.loadHQPagePreview | ||||||
| import com.ethran.notable.editor.utils.minus | ||||||
| import com.ethran.notable.editor.utils.plus | ||||||
| import com.ethran.notable.editor.utils.strokeBounds | ||||||
|
|
@@ -428,7 +432,7 @@ class PageView( | |||||
|
|
||||||
| // load background, fast, if it is accurate enough. | ||||||
| private fun loadInitialBitmap(): Boolean { | ||||||
| val bitmapFromDisc = loadPersistBitmap( | ||||||
| val bitmapFromDisc = loadHQPagePreview( | ||||||
| context = context, | ||||||
| pageID = currentPageId, | ||||||
| scroll = scroll, | ||||||
|
|
@@ -450,10 +454,7 @@ class PageView( | |||||
| // draw just background. | ||||||
| val backgroundType = pageDataManager.getBackgroundType() | ||||||
| if (backgroundType == BackgroundType.Native) { | ||||||
| val bg = pageDataManager.getBackgroundName() | ||||||
| drawBg( | ||||||
| context, windowedCanvas, backgroundType, bg, scroll, 1f, this | ||||||
| ) | ||||||
| drawBgToCanvas(null) | ||||||
| } else | ||||||
| windowedCanvas.drawColor(Color.WHITE) | ||||||
| return false | ||||||
|
|
@@ -666,18 +667,7 @@ class PageView( | |||||
|
|
||||||
| log.d("Redrawing full logical rect: $redrawRect") | ||||||
| windowedCanvas.drawColor(Color.BLACK) | ||||||
| val backgroundType = pageDataManager.getBackgroundType() ?: BackgroundType.Native | ||||||
| val bg = pageDataManager.getBackgroundName() | ||||||
| drawBg( | ||||||
| context, | ||||||
| windowedCanvas, | ||||||
| backgroundType, | ||||||
| bg, | ||||||
| scroll, | ||||||
| zoomLevel.value, | ||||||
| this, | ||||||
| redrawRect | ||||||
| ) | ||||||
| drawBgToCanvas(redrawRect) | ||||||
| pageDataManager.cacheBitmap(currentPageId, windowedBitmap) | ||||||
|
|
||||||
| drawAreaScreenCoordinates(redrawRect) | ||||||
|
|
@@ -823,6 +813,39 @@ class PageView( | |||||
|
|
||||||
| } | ||||||
|
|
||||||
| fun drawBgToCanvas(clipRect: Rect?) { | ||||||
| val backgroundType = pageDataManager.getBackgroundType() ?: BackgroundType.Native | ||||||
| val bg = pageDataManager.getBackgroundName() | ||||||
| val pageNumber = currentPageNumber | ||||||
| val scale = zoomLevel.value | ||||||
| val bgImage: Bitmap? = | ||||||
| when (backgroundType) { | ||||||
| BackgroundType.Image, BackgroundType.CoverImage, BackgroundType.AutoPdf, | ||||||
| is BackgroundType.Pdf, BackgroundType.ImageRepeating -> { | ||||||
| if (backgroundType is BackgroundType.Image && bg == "iris") { | ||||||
| val resId = R.drawable.iris | ||||||
| ImageBitmap.imageResource(context.resources, resId).asAndroidBitmap() | ||||||
| } else { | ||||||
| getOrLoadBackground(bg, pageNumber, scale) | ||||||
| } | ||||||
| } | ||||||
| BackgroundType.Native -> { | ||||||
| null | ||||||
| } | ||||||
| } | ||||||
| drawBg( | ||||||
| canvas = windowedCanvas, | ||||||
| backgroundType = backgroundType, | ||||||
| background = bg, | ||||||
| scroll = scroll, | ||||||
| resourceBitmap = bgImage, | ||||||
| scale = scale, | ||||||
| repeat = false, | ||||||
|
||||||
| repeat = false, | |
| repeat = backgroundType is BackgroundType.ImageRepeating, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drawBgToCanvasalways usespageNumber = currentPageNumberwhen loading backgrounds. ForBackgroundType.Pdf, the correct page index isbackgroundType.page, not the current on-screen page number (which is used forAutoPdf). As written, fixed-PDF backgrounds can render the wrong PDF page.