@@ -5232,61 +5232,11 @@ def prev_location(self, page_id):
52325232
52335233    def reload_page(self, page: Page) -> Page:
52345234        """Make a fresh copy of a page."""
5235-         old_annots = {}  # copy annot references to here
5236-         pno = page.number  # save the page number
5237-         for k, v in page._annot_refs.items():  # save the annot dictionary
5238-             old_annots[k] = v
5239-         
5240-         # When we call `self.load_page()` below, it will end up in
5241-         # fz_load_chapter_page(), which will return any matching page in the
5242-         # document's list of non-ref-counted loaded pages, instead of actually
5243-         # reloading the page.
5244-         #
5245-         # We want to assert that we have actually reloaded the fz_page, and not
5246-         # simply returned the same `fz_page*` pointer from the document's list
5247-         # of non-ref-counted loaded pages.
5248-         #
5249-         # So we first remove our reference to the `fz_page*`. This will
5250-         # decrement .refs, and if .refs was 1, this is guaranteed to free the
5251-         # `fz_page*` and remove it from the document's list if it was there. So
5252-         # we are guaranteed that our returned `fz_page*` is from a genuine
5253-         # reload, even if it happens to reuse the original block of memory.
5254-         #
5255-         # However if the original .refs is greater than one, there must be
5256-         # other references to the `fz_page` somewhere, and we require that
5257-         # these other references are not keeping the page in the document's
5258-         # list.  We check that we are returning a newly loaded page by
5259-         # asserting that our returned `fz_page*` is different from the original
5260-         # `fz_page*` - the original was not freed, so a new `fz_page` cannot
5261-         # reuse the same block of memory.
5262-         #
5263-         
5264-         refs_old = page.this.m_internal.refs
5265-         m_internal_old = page.this.m_internal_value()
5266-         
5267-         page.this = None
5268-         page._erase()  # remove the page
5235+         pno = page.number
52695236        page = None
52705237        TOOLS.store_shrink(100)
5271-         page = self.load_page(pno)  # reload the page
5272- 
5273-         # copy annot refs over to the new dictionary
5274-         #page_proxy = weakref.proxy(page)
5275-         for k, v in old_annots.items():
5276-             annot = old_annots[k]
5277-             #annot.parent = page_proxy  # refresh parent to new page
5278-             page._annot_refs[k] = annot
5279-         if refs_old == 1:
5280-             # We know that `page.this = None` will have decremented the ref
5281-             # count to zero so we are guaranteed that the new `fz_page` is a
5282-             # new page even if it happens to have reused the same block of
5283-             # memory.
5284-             pass
5285-         else:
5286-             # Check that the new `fz_page*` is different from the original.
5287-             m_internal_new = page.this.m_internal_value()
5288-             assert m_internal_new != m_internal_old, \
5289-                     f'{refs_old=} {m_internal_old=:#x} {m_internal_new=:#x}'
5238+         page = doc.load_page(pno)
5239+         page.refresh()
52905240        return page
52915241
52925242    def resolve_link(self, uri=None, chapters=0):
@@ -9742,10 +9692,8 @@ def read_contents(self):
97429692    def refresh(self):
97439693        """Refresh page after link/annot/widget updates."""
97449694        CheckParent(self)
9745-         doc = self.parent
9746-         page = doc.reload_page(self)
9747-         # fixme this looks wrong.
9748-         self.this = page
9695+         pdf_page = _as_pdf_page(self)
9696+         mupdf.pdf_sync_page(pdf_page)
97499697
97509698    @property
97519699    def rotation(self):
0 commit comments