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

Add getCharCoordinates() and getMark() functions to the Scripter API. #127

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

xavidotron
Copy link

Add two new functions to the Scripter API.

positionToPoint() lets you get information about where a given character in a text frame is located.
getMark() lets you get information about a mark in a text frame.

These two additions make it possible to write python scripts to add PDF links based on the content of a text frame.

@aoloe
Copy link
Contributor

aoloe commented Apr 22, 2020

hi @xavidotron , nice idea!

i've put some comments inline.

here is some more general feedback from my side:

  • i don't like the name positionToPoint(). it's already not much telling in the context of the story, it gets harder to understand in a script. i did not spend to much time on it, but i would go for something like getCharCoordinates() (you might want to look at other char related API functions to pick the right name)
  • i'm not sure that getMark() is the right approach for creating clickable links. you will need the python script to go through the whole text, which can be very slow. a getMarks() (for a given text frame / story. or even the whole document) will be much more efficient. if you don't want to introduce a data structure for the marks, the function could return the start and end position for the marks in the current frame / story.

Fix positionToPoint() to work with text frames that aren't the first in
a chain.
@xavidotron
Copy link
Author

Thanks for the review! The only other API function I see that operates on character positions is insertText(), though maybe I'm missing something, so I didn't come up with a better name than your suggestion.

I'm happy to add a getMarks() in addition if you want, but for my use case, since I need to go through the frame text with a regular expression to find places to link anyways, it seems more convenient to be able to get specific marks rather than getting all of them and then filtering out the ones I don't want. I'm also not sure how I'd implement getMarks() without iterating over the each position in the StoryText object in the C++, which doesn't seem like a significant win over doing it in python.

@aoloe
Copy link
Contributor

aoloe commented Apr 22, 2020

thanks for the further commits.

as far as i know, iterating with c++ is by orders of magnitudes faster than doing so with python (that's one of the selling points of numpy...).

anyway, i would love to see how you're managing the links through python!
imo at the end the goal should be to manage them in scribus itself, but collecting some experience with a python script seems to be a good idea to me!

@xavidotron
Copy link
Author

At the scale I'm operating at, iterating in python is plently fast enough and it's a lot quicker for me to write and test weird regexp code in python than in C++. I could see some version of this being reasonable for a Scribus built-in but my use is sufficiently idiosyncratic that I think doing it in python is pretty reasonable.

The messy python script I'm currently using is attached; it's a quick script for my particular book rather than trying to be anything general.

pglink.txt

@aoloe
Copy link
Contributor

aoloe commented Apr 24, 2020

please take into consideration what jean wrote in the official scribus bug tracker.

personally, i don't spot big issues anymore but i have two more comments:

  • you might add to the getCharCoordinates() documentation that there might be issues with the update of the layout.
  • Insert index out of bounds. is probably a wrong error message for getMark() (line 1405).

i also had a look at your script and i understand that your defining automatic links for page references.
is it correct?
if it is, it's inspiring to see how you're doing and i really wonder how scribus could support that natively in the future.
if you have any hint, please tell me / us : - )

@xavidotron xavidotron changed the title Add positionToPoint() and getMark() functions to the Scripter API. Add getCharCoordinates() and getMark() functions to the Scripter API. Apr 24, 2020
@xavidotron
Copy link
Author

Fixed the error message, and added some documentation about layout.

Yes, this is to automatically add links for page references. The challenges I see with a built-in feature include:

  • https://bugs.scribus.net/view.php?id=14175 making it fiddly to get page references to point to the right page
  • What text to include in the link besides the page number probably varying a lot from document to document.

If that first bug gets fixed and someone added some sort of configuration to address the second, a built-in version of this could work pretty well.

@aoloe
Copy link
Contributor

aoloe commented Apr 24, 2020

nice

did you also test the case when parts of the text is overflowing and is hidden? (of course, it's a bad idea to have overflowing text, but thing happen...)
i don't see traces of it...

@xavidotron
Copy link
Author

Thanks for the reminder, added an additional check to raise an exception in this case (previously it would crash, oops).

@aoloe
Copy link
Contributor

aoloe commented May 12, 2020

hi, i guess it's time to submit a new diff to the official bug tracker...

i have not seen a definitive one in there...

@xavidotron
Copy link
Author

Is there a standard format of diff I should be putting there, or instructions I should be following?

@aoloe
Copy link
Contributor

aoloe commented May 13, 2020

i do them by adding .diff to the pull request url, saving the resulting text file and upload that to the bug tracker:

in this case, the diff can be created with:
https://patch-diff.githubusercontent.com/raw/scribusproject/scribus/pull/127.diff

(or you can of course do a git diff on your computer. but for that it would have been easier if you would have first created a feature branch... for the next time : - )

xavidotron and others added 3 commits May 27, 2020 00:12
…ment menu

item. Make getMark() return a dictionary. Add a setMarkText() function.
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

Successfully merging this pull request may close these issues.

2 participants