Skip to content
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

Show page number or save marks on disk #35

Open
henkye opened this issue May 7, 2020 · 2 comments
Open

Show page number or save marks on disk #35

henkye opened this issue May 7, 2020 · 2 comments

Comments

@henkye
Copy link

henkye commented May 7, 2020

Hi, jfbview is actually very neat viewer.
I'd love to have it one more feature:

  • ability to show current page.

Why? I'd love to continue reading book another day from last read page. This way, i could note page number somewhere and then jump right to it.

What would also solve this would be permanent marks between jfbviews reexecutions. But i guess, this would be rather more complicated.

I actually looked at code, and was lost. I do some higher level programming and a little bit of plain C, but this is complete gibberish for me :)

@henkye
Copy link
Author

henkye commented Aug 18, 2020

Well, i was so inspired, i've made a patch for it:

--- a/src/viewer.cpp    2020-05-28 01:23:54.000000000 +0200
+++ b/src/viewer.cpp    2020-08-18 11:37:14.449219924 +0200
@@ -152,6 +152,14 @@
     _render_cache.Prepare(
         RenderCacheKey(page + 1, zoom, _state.Rotation, _state.ColorMode));
   }
+
+  // 7. Write page number to file.
+  FILE*        filePointer1;
+  filePointer1 = fopen("/tmp/jfbview-last-page", "w");
+  if (filePointer1 == NULL) fprintf(stderr, "Warning: error opening file: '/tmp/jfbview-last-page'\n");
+
+  fprintf(filePointer1, "%d\n", ++page);
+  fclose(filePointer1);
 }

 void Viewer::GetState(Viewer::State* state) const {

Then, you can wrap around something like this:

#
# $obj is path to PDF file
#
function jfb() {
	read sum none < <(sha256sum <<< "$obj")

	read _sum num < <(grep "^${sum}" ~/.jfb-history)

	if [[ -n "$num" ]]; then
		jfbview -p "$num" "$obj"
	else
		jfbview "$obj"
	fi

	( grep -v "^${sum}" ~/.jfb-history; echo "$sum	$(cat /tmp/jfbview-last-page)" ) > /tmp/.jfb-history
	mv -f /tmp/.jfb-history ~/.jfb-history
}

In this combination, it will:

  • save last open page of PDF to file
  • automatically start on that page next time you open PDF

Just like Evince do by default.

It's rather crude from style perspective, but should be safe to use.

@henkye
Copy link
Author

henkye commented Aug 20, 2020

fix + show page number:

  // 7. Write page number to file.
  FILE*	filePointer1;
  filePointer1 = fopen("/tmp/jfbview-last-page", "w");
  if (filePointer1 == NULL) fprintf(stderr, "Warning: error opening file: '/tmp/jfbview-last-page'\n");

  fprintf(filePointer1, "%d\n", page + 1);
  fclose(filePointer1);
  printf("\033[0;0H");
  printf("%d\n", page + 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant