|
@@ -194,9 +194,24 @@ try:
|
|
|
comp = desktop.getCurrentComponent()
|
|
comp = desktop.getCurrentComponent()
|
|
|
draw = comp.DrawPages
|
|
draw = comp.DrawPages
|
|
|
total = draw.Count
|
|
total = draw.Count
|
|
|
|
|
+ current = 0
|
|
|
try:
|
|
try:
|
|
|
controller = comp.getCurrentController()
|
|
controller = comp.getCurrentController()
|
|
|
- current = controller.getCurrentPage().PageIndex + 1
|
|
|
|
|
|
|
+ # During slideshow: PresentationController has getCurrentSlideIndex()
|
|
|
|
|
+ if hasattr(controller, 'getCurrentSlideIndex'):
|
|
|
|
|
+ current = controller.getCurrentSlideIndex() + 1
|
|
|
|
|
+ print(f"[status] slideshow mode, index={current}", file=sys.stderr)
|
|
|
|
|
+ # Editor mode: DrawController has getCurrentPage()
|
|
|
|
|
+ elif hasattr(controller, 'getCurrentPage'):
|
|
|
|
|
+ page = controller.getCurrentPage()
|
|
|
|
|
+ # page.PageIndex may not exist on all objects; use DrawPages index
|
|
|
|
|
+ for i in range(draw.Count):
|
|
|
|
|
+ if draw.getByIndex(i) == page:
|
|
|
|
|
+ current = i + 1
|
|
|
|
|
+ break
|
|
|
|
|
+ print(f"[status] editor mode, index={current}", file=sys.stderr)
|
|
|
|
|
+ else:
|
|
|
|
|
+ print(f"[status] unknown controller type: {type(controller)}", file=sys.stderr)
|
|
|
except Exception as inner:
|
|
except Exception as inner:
|
|
|
print(f"[status] could not get current page: {inner}", file=sys.stderr)
|
|
print(f"[status] could not get current page: {inner}", file=sys.stderr)
|
|
|
current = 0
|
|
current = 0
|
|
@@ -229,22 +244,26 @@ try:
|
|
|
draw = comp.DrawPages
|
|
draw = comp.DrawPages
|
|
|
print(f"[slideImage] total slides: {draw.Count}", file=sys.stderr)
|
|
print(f"[slideImage] total slides: {draw.Count}", file=sys.stderr)
|
|
|
slide = draw.getByIndex(${index - 1})
|
|
slide = draw.getByIndex(${index - 1})
|
|
|
- print(f"[slideImage] got slide object: {slide}", file=sys.stderr)
|
|
|
|
|
|
|
+ print(f"[slideImage] got slide: {slide.Name}", file=sys.stderr)
|
|
|
tmp = tempfile.mktemp(suffix='.png')
|
|
tmp = tempfile.mktemp(suffix='.png')
|
|
|
print(f"[slideImage] exporting to: {tmp}", file=sys.stderr)
|
|
print(f"[slideImage] exporting to: {tmp}", file=sys.stderr)
|
|
|
graphicExporter = smgr.createInstanceWithContext(
|
|
graphicExporter = smgr.createInstanceWithContext(
|
|
|
"com.sun.star.drawing.GraphicExportFilter", ctx)
|
|
"com.sun.star.drawing.GraphicExportFilter", ctx)
|
|
|
|
|
+ # setSourceDocument must be called with the slide (DrawPage)
|
|
|
graphicExporter.setSourceDocument(slide)
|
|
graphicExporter.setSourceDocument(slide)
|
|
|
- props = []
|
|
|
|
|
def mkprop(name, val):
|
|
def mkprop(name, val):
|
|
|
p = PropertyValue()
|
|
p = PropertyValue()
|
|
|
p.Name = name
|
|
p.Name = name
|
|
|
p.Value = val
|
|
p.Value = val
|
|
|
return p
|
|
return p
|
|
|
- props.append(mkprop("URL", uno.systemPathToFileUrl(tmp)))
|
|
|
|
|
- props.append(mkprop("MediaType", "image/png"))
|
|
|
|
|
- props.append(mkprop("Selection", slide))
|
|
|
|
|
- graphicExporter.filter(tuple(props))
|
|
|
|
|
|
|
+ # Do NOT pass Selection — setSourceDocument is sufficient
|
|
|
|
|
+ props = (
|
|
|
|
|
+ mkprop("URL", uno.systemPathToFileUrl(tmp)),
|
|
|
|
|
+ mkprop("MediaType", "image/png"),
|
|
|
|
|
+ mkprop("PixelWidth", 800),
|
|
|
|
|
+ mkprop("PixelHeight", 600),
|
|
|
|
|
+ )
|
|
|
|
|
+ graphicExporter.filter(props)
|
|
|
if os.path.exists(tmp):
|
|
if os.path.exists(tmp):
|
|
|
size = os.path.getsize(tmp)
|
|
size = os.path.getsize(tmp)
|
|
|
print(f"[slideImage] exported file size: {size} bytes", file=sys.stderr)
|
|
print(f"[slideImage] exported file size: {size} bytes", file=sys.stderr)
|
|
@@ -540,14 +559,17 @@ async function handleCmd(cmd: string): Promise<void> {
|
|
|
console.log(`[cmd] result: current=${current} total=${total}`);
|
|
console.log(`[cmd] result: current=${current} total=${total}`);
|
|
|
broadcast({ event: "slide", current, total });
|
|
broadcast({ event: "slide", current, total });
|
|
|
|
|
|
|
|
- if (current > 0 && cmd !== "end") {
|
|
|
|
|
- console.log(`[cmd] requesting slide image for index=${current}`);
|
|
|
|
|
- const b64 = await driver.slideImage(current);
|
|
|
|
|
|
|
+ // Request image: use current if known, fall back to 1 for navigation cmds
|
|
|
|
|
+ // where slideshow may be active but status returned 0
|
|
|
|
|
+ const imageIndex = current > 0 ? current : (cmd !== "end" && total > 0 ? 1 : 0);
|
|
|
|
|
+ if (imageIndex > 0) {
|
|
|
|
|
+ console.log(`[cmd] requesting slide image for index=${imageIndex}`);
|
|
|
|
|
+ const b64 = await driver.slideImage(imageIndex);
|
|
|
if (b64) {
|
|
if (b64) {
|
|
|
console.log(`[cmd] broadcasting image, base64 length=${b64.length}`);
|
|
console.log(`[cmd] broadcasting image, base64 length=${b64.length}`);
|
|
|
broadcast({ event: "image", data: b64 });
|
|
broadcast({ event: "image", data: b64 });
|
|
|
} else {
|
|
} else {
|
|
|
- console.warn(`[cmd] slideImage returned empty for index=${current}`);
|
|
|
|
|
|
|
+ console.warn(`[cmd] slideImage returned empty for index=${imageIndex}`);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|