I'm currently using React Native's Text component like this
<Text numberOfLines={2} ellipsizeMode="tail">Some long texts...</Text>
This renders texts like this
First line
Second lineā¦
I'd like to use different ellipsis, for example,
Instead of
End of a long line...
It would be
End of a long line ...More
Currently, possible solutions would be:
Count the number of characters and cut the string then concatenate custom ellipsis.
Problem: Font's width differs per character.
Use ellipsizeMode="clip" and create absolutely positioned View with a custom ellipsis.
Problem: Can't programmatically tell when the Text is clipped.
Does anyone have a solution?
Related
I have two issues with how PyQt is formatting my QLabels
Issue 1:
When hyperlinks are added it displays as if there were no newlines in the string.
For the input text:
https://www.google.co.uk/
https://www.google.co.uk/
https://www.google.co.uk/
It's shown like this without newlines
Issue 2: Sometimes PyQt just doesn't even detect the 'a' tag this happens when the start of string is not a hyperlink but it is then followed by newlines with hyperlinks e.g. this input:
test
https://www.google.co.uk/
https://www.google.co.uk/
https://www.google.co.uk/
As you can see the newlines are properly shown but PyQt has no longer detected the hyperlinks
From the text property documentation of QLabel:
The text will be interpreted either as plain text or as rich text, depending on the text format setting; see setTextFormat(). The default setting is Qt::AutoText; i.e. QLabel will try to auto-detect the format of the text set.
The AutoText flag can only make a guess using simple tag syntax checks (basic tags without arguments, such as <b>, or document type declaration headers, like <html>).
This is obviously done for performance reasons.
If you are sure that you're always setting rich text content, use the appropriate Qt.TextFormat enum:
label.setTextFormat(QtCore.Qt.RichText)
Using the HTML-like syntax of rich text will obviously use the same basic concept HTML had since its birth, almost 30 years ago: line breaks between any word in the document (text or tag) are ignored, as much as multiple spaces are always considered as one.
So, if you want to add line breaks, you have to use the appropriate <br> (or <br/> for xhtml) tag.
Also remember that Qt rich text engine has a limited support, as described in the documentation about the Supported HTML Subset.
As a coding challenge, I've been building a rich-text editor. So far, I've made working save/save as/load systems and working Headers. But, when you save as .txt all the heading data is lost. So I've been thinking about doing a system that relies on '#' to mark headers (basically syntax highlighting)(#-H1,##-H2,###-H3...). I've looked around, and haven't found anything of the sort. So far, I use this as my system of headings:
editor.tag_configure('heading7', font=heading7_font)
removeTags()
editor.tag_add('heading7', SEL_FIRST, SEL_LAST)
*heading7_font=("Consolas Bold", 16), removeTags(): lists through tags and removes all.
Basically, you just select on an OptionMenu if you wish to change the fontsize (or use a certain bind). This question is problably too vague, but, I would very much like so direction or an answer.
Here's the code of my entire project (YES, I know I'm not using classes, and it's a jittery mess, but, I'm going to work on that later): https://pastebin.com/wthVT6q4 (Here's the stylesheet variables: https://pastebin.com/WrX4EDKM)
You can use the text widget search method to search for a string or a pattern. Then it's just a matter of applying the tag to the results.
This is how it is documented in the Text class:
search(self, pattern, index, stopindex=None, forwards=None, backwards=None, exact=None, regexp=None, nocase=None, count=None, elide=None)
Search PATTERN beginning from INDEX until STOPINDEX.
Return the index of the first character of a match or an
empty string.
As you can see, you can use the search method to search on a regular expression. Since you won't always know the length of the matched text, you can specify an IntVar to be given the count of the matching characters.
For example, to search for a line that begins with ## you can do something like this:
count_var = tk.IntVar()
index = editor.search(r'## .*', "1.0", "end", count=count_var, regexp=True)
With that, you can use index as the start of the range, and "{} +{} chars".format(index, count_var.get()) for the end of the range. Or, use "{} lineend".format(index)" to add the highlight to the entire line.
If you only want to highlight the characters after ##, you can adjust index in a similar way: "{}+{}chars".format(index, 3)
Note: the regular expression syntax must follow the rules of Tcl regular expressions. Conceptually the same, they differ from python's rules in some of the special character classes.
I am trying to do what the Title says, Configure the Tkinter message so that each tuple in WL_ratios has its own line without being surrounded in brackets. Creating more messages is not an option as the length of WL_ratios can vary, so i have to only use the one.
#(below) is in the __init__ of the class
self.Leaderboardtext = Message(self.LeaderboardFrame,text="",width=100)
self.Leaderboardtext.pack()
#this (below) is in another function in the same class.
WL_ratios = [["james",3]["harrison",2]["jo",1]]
self.Leaderboardtext.configure(text="Leaderboard: {0}".format(WL_ratios))
So far the width=100 is the only thing that is allowing me to get text onto a new line. However this still isnt working because each tuple varies in length so some tuples spread across two lines which isnt what i want. I know you could limit each line by how number of characters but again the tuples vary in character length so i dont think that is an option.
Does anyone have any suggestions that could work?
Just convert each tuple into a string, and add \n there, and that should do it. Alternatively, you could call each value in the tuple separately, and add \n there.
So I have a font that i made a while back din't do very much of anything with it at the time, i lost a few of the original SVGs when i have reinstalled the OS on my computer, The font is full unicode with lots of characters, all the icons saved in the font are outside the normal character range, i know it is possible to extract a bunch of SVG from the font using this command
fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export("svg"); endloop;' Typeface.ttf
and
fontforge -lang=ff -c 'Open($1); SelectAll(); foreach Export("svg"); endloop;' Typeface.ttf
However the first misses the icons completely, and the second is no different. all the icons are between two points in the file starting at U+e000 and going through to U+e17d i want to know how i can extract all the icons between these two points. and if possible match with a namelist.txt for naming.
How to extract several characters between two Unicode values from fontforge?
The conceptually cleanest way would be to iterate over the hexadecimal number-range you specified and call font[char_name].export() on every single one of them. However, this comes with the hassle of incrementing hexadecimal numbers (which while feasible is a bit more involved than what I'm going to propose).
The following for-loop paired with the function 'nameFromUnicode(position)' should do the trick while staying (mostly) clear of hexadecimals. The function 'nameFromUnicode(position)' takes the position of a Unicode character as an integer and returns the name of the character at that position (something like Uni2D42). This name can then be passed to font[that_char_name].export() to export it. To find the starting and ending position of your range in decimal simply interpret the character names as a hexadecimal number and convert it to decimal. In your case e000 becomes 57344 and e17d becomes 57725. The range in decimal would then be from 57344 to 57725.
The following code snippet is a bare bone loop extracting the characters in the specified range (although for '.png' instead of '.svg'; adapting it should be fairly straight forward though).
from fontforge import *
font = open("/path/to/your/.ttf/file")
for position in range(57344,57726):
glyph = nameFromUnicode(position)
font[glyph].export(font[glyph].glyphname + ".png", 150)
I don't quite understand your second question about matching against a namelist.txt. If after 5 years you still crave an answer your welcome to elaborate and I'll see if I can come up with an answer.
I've converted my PDF file into a long string using PDFminer.
I'm wondering how I should go about dividing this string into smaller, individual strings/pages. Each page is divided by a certain series of characters (CRLF, FF, page number etc), and the string should be split and appended to a new text file according to these characters occurring.
I have no experience with regex, but is using the re module the best way to go about this?
My vague idea for implementation is that I have to iterate through the file using the re.search function, creating text files with each new form feed found. The only code I have is PDF > text conversion. Can anyone point me in the right direction?
Edit: I think the expression I should use is something like ^.*(?=(\d\n\n\d\n\n\f\bFavela\b)) (capture everything before 2 digits, the line breaks and the book's title 'Favela' which appears on top of each page.
Can I save these \d digits as variables? I want to use them as file names, as I iterate through the book and scoop up the portions of text divided by each appearance of \f\Favela.
I'm thinking the re.sub method would do it, looping through and replacing with an empty string as I go.