Skip to content

Basic analysis of the script content of strings#764

Merged
jwiggins merged 2 commits into
masterfrom
feature/language-parse
Mar 30, 2021
Merged

Basic analysis of the script content of strings#764
jwiggins merged 2 commits into
masterfrom
feature/language-parse

Conversation

@jwiggins
Copy link
Copy Markdown
Member

This is another part of #762

There are two pieces here, and a ton of machine-generated code (don't fear the diff):

  • A small program which fetches http://www.unicode.org/Public/UNIDATA/Scripts.txt, parses it, and writes out the kiva.fonttools.text._data module.
  • A new class UnicodeAnalyzer which uses the data from Scripts.txt and returns the languages and slices for a given input string.

UnicodeAnalyzer is pretty basic right now. I'd like to keep it that way in this PR. For instance, Emoji ligatures are not great:

In [3]: s = "👩‍👩‍👧‍👧" 

In [4]: s                                                                       
Out[4]: '👩\u200d👩\u200d👧\u200d👧'

In [5]: an.languages(s)                                                         
Out[5]: 
[(0, 1, 'Common'),
 (1, 2, 'Inherited'),
 (2, 3, 'Common'),
 (3, 4, 'Inherited'),
 (4, 5, 'Common'),
 (5, 6, 'Inherited'),
 (6, 7, 'Common')]

Comment thread kiva/fonttools/_util.py
Comment on lines +113 to +114
94: "Tai_Le",
95: "New_Tai_Lue",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were changed to match the names in kiva.fonttools.text._data.

Copy link
Copy Markdown
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


def _lookup_codepoint(self, cp):
comps = self.ranges - ord(cp)
index = ((comps[:, 0] <= 0) == (comps[:, 1] >= 0)).argmax()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the most important detail in the PR - how we're selecting the entry given a code point - and it'd be useful if you could elaborate on how we're doing it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

@rahulporuri
Copy link
Copy Markdown
Contributor

still LGTM

@jwiggins jwiggins merged commit ffd2535 into master Mar 30, 2021
@jwiggins
Copy link
Copy Markdown
Member Author

Thanks for the review

@jwiggins jwiggins deleted the feature/language-parse branch March 30, 2021 09:09
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