From 88d947e2ac2f522fe88556803f7797eddd7575da Mon Sep 17 00:00:00 2001 From: Borgal Date: Wed, 25 Mar 2026 01:33:11 +0100 Subject: [PATCH] Fix: Text-Highlights (GlyphRange) in annotierten PDFs sichtbar machen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - merge-annotations.py: rmscene GlyphRange-Blöcke auslesen und als SVG-Rects rendern - Koordinaten: rmscene screen-px × 72/226 → SVG-Punkte (identisch mit rmc-Skalierung) - Farben: fill='rgb(...)' + fill-opacity statt rgba() (Inkscape-Kompatibilität) - Highlights werden VOR Stift-Annotationen eingefügt (korrekte Z-Order) - Dockerfile: rmscene==0.6.1 (rmrl+rmscene>=0.7.0 waren inkompatibel mit rmc) --- remarkable/Dockerfile | 2 +- remarkable/scripts/merge-annotations.py | 40 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/remarkable/Dockerfile b/remarkable/Dockerfile index 7ad463d..8dd19fe 100755 --- a/remarkable/Dockerfile +++ b/remarkable/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # rmc + Farb-Patch -RUN pip3 install "rmc==0.3.0" "rmscene>=0.7.0" "pypdf" "rmrl" --break-system-packages --ignore-installed packaging \ +RUN pip3 install "rmc==0.3.0" "rmscene==0.6.1" "pypdf" --break-system-packages --ignore-installed packaging \ && python3 - <<'EOF' import pathlib import rmc.exporters.writing_tools as m diff --git a/remarkable/scripts/merge-annotations.py b/remarkable/scripts/merge-annotations.py index 5a6121e..961d920 100755 --- a/remarkable/scripts/merge-annotations.py +++ b/remarkable/scripts/merge-annotations.py @@ -94,6 +94,46 @@ for i in range(n_pages): inner_m = re.search(r']*>(.*)', svg, re.DOTALL) inner = inner_m.group(1) if inner_m else '' + # GlyphRange-Highlights (Textmarkierungen) aus .rm lesen + highlight_svg = '' + try: + import rmscene + RM_SCALE = 72.0 / 226 # rmscene screen-px → SVG-Punkte (wie rmc) + HIGHLIGHT_COLORS = { + 9: ('rgb(255,235,0)', 0.4), # HIGHLIGHT (gelb) + 3: ('rgb(251,247,25)', 0.4), # YELLOW + 4: ('rgb(0,255,0)', 0.4), # GREEN + 5: ('rgb(255,192,203)', 0.4), # PINK + 6: ('rgb(78,105,201)', 0.4), # BLUE + 7: ('rgb(179,62,57)', 0.4), # RED + } + with open(page_rm[i], 'rb') as rmf: + blocks = list(rmscene.read_blocks(rmf)) + for block in blocks: + if not (hasattr(block, 'item') and hasattr(block.item, 'value')): + continue + glyph = block.item.value + if not hasattr(glyph, 'rectangles'): + continue + try: + color_id = int(glyph.color) + except Exception: + color_id = 9 + fill, opacity = HIGHLIGHT_COLORS.get(color_id, ('rgb(255,235,0)', 0.4)) + for rect in glyph.rectangles: + highlight_svg += ( + f'\n' + ) + except Exception as e: + print(f' GlyphRange Fehler: {e}', flush=True) + + # Highlights VOR den Stift-Annotationen einblenden + if highlight_svg: + print(f' {highlight_svg.count(" PNG-Pixel pts_to_px = png_w / pdf_w_pt