Skip to content

Commit

Permalink
Made compatible with fpdf2 v2.7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Jan 30, 2024
1 parent 94fdfb7 commit 1f44850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pdf_game/reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from contextlib import contextmanager
from textwrap import indent

from fpdf.image_datastructures import ImageCache

from .assigner import assign_page_ids
from .entities import GameMilestone
from .optional_deps import tqdm
Expand Down Expand Up @@ -87,7 +89,7 @@ def render_victory_noop(*_): pass
class FakePdfRecorder:
'Fake fpdf.FPDF class that must implement all the methods used during the pages rendering'
def __init__(self):
self.images = {} # images cache used by get_image_info
self.image_cache = ImageCache()
self._calls = []
self._links = {}

Expand Down
11 changes: 2 additions & 9 deletions pdf_game/render_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .entities import Position
from .js import action, REL_RELEASE_DIR

from fpdf.image_parsing import get_img_info
from fpdf.image_parsing import get_img_info, preload_image


BACKGROUNDS = 'black,nightsky,tempest,interior'.split(',')
Expand Down Expand Up @@ -126,12 +126,5 @@ def link_from_page_id(pdf, page_id):


def get_image_info(pdf, img_filepath):
# Replicates some logic from FPDF.image().
# Could be exposed as a FPDF method with a minor refactor.
info = pdf.images.get(img_filepath)
if not info:
info = get_img_info(img_filepath)
pdf.images[img_filepath] = info
info['i'] = len(pdf.images)
info['usages'] = 1
name, img, info = preload_image(pdf.image_cache, img_filepath)
return info

0 comments on commit 1f44850

Please sign in to comment.