[Revised]
I am trying GTK3 TextView, in C. I know how to apply tags, such as italics, etc., to a region of text.
But how do I "turn on" a style (italics, bold, etc) while typing in the buffer? For example, suppose I am typing text and there are no styles set. Then I want to type in italics. I want to apply the italic tag to the insert point, after which whatever I typed would be in italics.
I notice that when you place the insert cursor to the right of any existing styled text, the tags of the previous character are inherited, but only if the style is in effect before and after the insert point. Interestingly, the trailing newline can be stylized, so when the insert point is at the end of a line and the last visible character has a style, then that style is inherited.
I've looked at some methods that use a key-press signal and then apply a text tag to the region of the untagged character just typed, but that is slow and looks odd on screen -- the plain char is displayed and then replaced by the tagged char.
I've also tried:
gtk_text_buffer_insert_markup(buf, &iter, "<i>", -1);
but that gets a Warning: Invalid markup string: ... Element 'markup' was closed, but the currently open element is 'i' and has no effect on the displayed text. Using <i></i> gets no warning but also has no effect. I finally resorted to:
gtk_text_buffer_insert_markup(buf, &iter, "<i> </i>", -1); // 2 spaces
gtk_text_iter_backward_char (&iter);
gtk_text_buffer_place_cursor(buf, &iter);
which lets me start typing in italics between 2 new spaces -- that's not so bad.
But clicking an "I" button to start typing in italics -- that is a basic editing function that has been around for decades. It must be possible in GTK somehow?
Any ideas?
thanks
Related
I have a text field which I need to style for example with bold or italics parts.
I tried overridding the TextEditingController's buildTextSpan and formatting the text using annotation ranges with custom styles but the edge cases were too much and I really couldn't get it to work.
So, thought about using a formatter where before every change in format I'll add a custom character, like this:
This text is |bBOLD and this is |iITALICS. Would get me this:
This text is BOLD and this is ITALICS. So I override the buildTextSpan to build the TextSpan from a parse function where I split the text by the special characters and check the initial letter of each text for formatting info.
This works well except for the fact that when I press the right arrow to go the next character after the "This text is ", the cursor will stay fixed as it thinks there are two characters but being only for formatting, they aren't there on the render.
Is there any way I could tell the textfield to ignore certain characters when selecting, moving selection or typing?
I think this would work!
static const kCharToBEIgnored = 0x2C;
// Here 0x2C means ',' comma
// For complete list visit https://api.flutter.dev/flutter/charcode/charcode-library.html
String get text {
return String.fromCharCodes(
_value.text.codeUnits.where((ch) => ch != kCharToBEIgnored),
);
}
I set org-hide-emphasis-markers to true in my init file, so that all text marked as *bold* just shows up as bold. But now I'm wondering how to toggle this formatting on/off without making these characters visible again... is there a key binding for this? How about italics and underline?
Thanks!
-Adam
[This is a workaround, not a solution]
If you place the cursor after the bold text and press C-d, the trailing asterisk is deleted and the leading markup becomes visible. Similarly, if you place the cursor before the bold text and press C-d, the leading asterisk is deleted and the trailing markup becomes visible.
I am trying to simulate Word's displaying of non-printing characters. There is no problem with all of them but anchors and I didn't found any info related to them. Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
Thank you for answer
The anchor, unlike most non-printing characters, can never print. It's merely a visual aid to inform the user with which paragraph or character a graphic with text flow formatting is associated. It's not possible to detect an anchor directly in the document text using Word's API (object model). It's bound to the graphic and would require analyzing the properties of the Shape object.
It could be determined by analyzing the document's WordOpenXML, although the term "anchor" is not used. The information could be deduced from the location and settings of the nodes that define where and how the graphic appears.
Is anchor special character placed in text or is it parameter of floating object and just displayed as special character?
I'm going to try to answer the "is it in text" question.
If, while debugging, you try to get a textual character for an anchor from a range's text, it won't be there. There won't even be a 0-width non-visible character there, like when you move a text cursor to the right past a non-printable character, but it doesn't actually move because there's something there (this may be editor-dependent, I have Notepad++ in mind).
So no, it's not in text.
But, at the same time, it will interfere with searches. E.g. If you put the word "text" on a line, put a text box on that line to create an anchor, and then search for "^13text" (with wildcards enabled, ^13 means the end-of-paragraph mark), it won't find it.
So yes, it must be in text because it interferes with searches.
So this might be a contradiction, but let's keep going. If it's in text, where is it? If you place the text cursor on the previous line, hold shift, and move it once to the right, the text box will be highlighted.
So it must be at the start.
But, there is also evidence that contradicts this. If you have a field at the start of the line with text on it, you can move it once to the right as before, and then once to the left, and though you have part of the line highlighted, the text box won't be part of the selection.
So, I really have no idea whether it's text or not, or where it is if so, but hopefully this helps someone else.
In Visio 2013, I have a connector that is in a container that has a gray background color. I successfully changed the background color of the text block by following these steps:
Double-click the connector
Expand the font options by clicking on the icon in the lower-right portion of the 'Home > Font' ribbon area
Click on 'Text Block' tab in the 'Text' dialog
Select 'Solid color' and choose the background color that matches the gray container background color
That works as expected - my text background color is no longer the default white; it now matches the background color of the container.
However, I want to add spacing to the left and right of the text. I tried increasing the margins in the same 'Text Block' tab of the 'Text' dialog mentioned above. This increased the margins but did not extend the background color of the text. A also tried manually adding spaces to the left and right of the text. The leading spaces worked, but the trailing spaces where truncated. Is there any way to add left and right padding to the text (similar to css padding)?
Modifying the text block location/size may give you what you want, combined with text margins.
To modify the text block location, you have to click the text block tool, which is on a dropdown with the text tool (at least in Visio 2003).
I know this is an old question, but I had the same question myself and wasn't able to (quickly) find an answer out there either. I finally hit upon a trick that'll get the result we're looking for:
Instead of spaces, add leading and trailing characters to the longest line in the text box. (I use ".")
Change the color of ONLY those added characters so it matches the text box's background.
The text box's background reaches to the furthest edge of the text within, and we're just using that to get what we want. Since it's just moving the edge indirectly, I consider it a "trick" that we can use instead of a "fix".
Quick list of Cons:
The text box background color has to be solid, or close to it.
The "invisible" text will still exist, so it'll show up in a copy/paste of the text.
Similarly, it may make Searching/CTRL+F for things within the document/file more difficult.
You can use No-Break Space. Insert it from Insert > Symbol.
I can write Arabic/Urdu/Persian on MS Word or Notepad just fine, but whenever I insert any English word or number, the sequence is just disturbed and seems like the all the words have been shuffled in the sentence.
Look at the example below:
یہ ایک مثال ہے اردو کی ...
Now I inserted an English word and it became:
یہ ایک مثال ہےword اردو کی ...
So you can see almost all of the words have been jumbled ... what is the solution for that ?
For example:
باللغة العربية “keyboard” انا أريد أن أعرف الكلمة
Finish typing the Arabic word and add a space after it (this space separates the embedded text from the Arabic text to its right).
Insert special character U+200F (to render the preceding space an Arabic character). The character name is "Right to Left Mark".
Insert special character U+202A (to begin the left-to-right embedding). The character name is "Left to Right Embedding".
Insert another space (to separate the embedded text from the Arabic text that will continue to its left).
Change the keyboard to e.g. English and type the left-to-right word.
Insert special character U+202C (to restore the bidrectional state to what it was before the left-to-right embedding). The Character name is "Pop directional formatting".
Change the keyboard back and continue writing in Arabic.
If you're working in Microsoft Office or Open Office, the "special characters" can be found under "insert" [Insert -> symbols -> other symbols -> special characters in MS 2013]. Scroll through until you find the character with the appropriate Unicode number, and if the Unicode number does not appear in your version of MS Word, select it by its name [as indicated above].
You can also add the character by writing it's unicode and then selecting it and pressing Alt+X - but that can be confusing because it needs constant change between Arabic and English.
All of the special characters involved in this little manoeuvre are invisible characters (their job is simply to change the direction of the text) so don't be surprised if it looks like you're not inserting anything.
Pay attention to select the RTL option from the ribbon when the majority of your paragraph is RTL and keep it selected [as shown in the picture in this answer https://stackoverflow.com/a/46050171/8558867 ].
Before you start typing in Arabic/Persian make sure you have chosen "Right-to-Left-Direction" button. This button can be found on Paragraph tab just left side of AZ sorting button. Also select "Align Text Right" button which can be found in Paragraph tab left side of Justify button.
Start typing your language
Before putting an English word put an space then select left ALT + SHIFT and type your English word
Once finished your English words select right ALT + SHIFT and then put a space and keep typing your language again
Hope this helps
This is OK; they're not shuffled: you're seeing them in LTR rendering mode.
You just need to make them right-to-left. In Notepad or Word, press right Ctrl+Shift to make their direction right-to-left and it will be okay. (It's like having <p dir="rtl">...</p> in HTML).
The control characters LRE and RLE (0x202A and 0x202B) and also LRM and RLM (0x200E and 0x200F) need to be applied to the whole paragraph, i.e they should come at the beginning of the sequence. Some text display widgets of some platforms may discard these control characters though, particularly older (pre-2000) platforms or those who do not support Unicode bidirectional algorithm correctly. Newer OS'es and programs should be fine; try with Windows Notepad for example.
I personally recommend using the platform's means to make the text RTL, and avoid special control characters because they're invisible and may cause surprising results if they go out of control. So you'd better use Word's API to make the text RTL, or if your output is HTML put them in <div dir="rtl">...</div> tags. For plain text file, user has to manually press the Ctrl+Shift keys himself.
Edit: this was written as a clarification answer to the first answer here, I later edited the first answer and added the important notes I wrote here [the edit still needs approval though].
I was able to fix my text by following the steps in the first answer here.
In case anyone faces troubles while following the steps, let me clarify some things:
If you are entering an English word in an Arabic text, make sure that RTL option in the ribbon is selected [circled in red in the following figure]:
Keep it selected throughout the paragraph irrespective of the language you are using [as long as the majority of the paragraph is written in an RTL language like Arabic or Hebrew].
Where to find the special characters and how to insert them:
You can write the unicode of the character and then select it and press "Alt + X". However, this can be a bit confusing because of the need to change back and forth between English and Arabic to write the codes, so the best thing to do is enter them 'manually' by inserting their names.
You can do that by going to Insert -> Symbol -> More Symbols -> Special characters [scroll down]. Then select the name of the characters you need to use instead of its unicode.
The names of the characters you'll need to use [as specified in the first answer here] are:
"Right to Left Mark" : U+200F.
"Left to Right Embedding": U+202A.
"Pop Directional Formatting": U+202C.
As the first answer says, nothing will appear on the screen because it's a non-printing character, so it's normal if you felt like nothing happened when you insert.
If you need to do it the other way around, that is, insert a Hebrew or Arabic word in an English text, just reverse the use of unicodes -- Or follow the steps in the following link: https://superuser.com/a/1247476/767967
If you want to know more about what the special characters do and what it means to make your paragraph LTR or RTL, visit the following link: http://dotancohen.com/howto/rtl_right_to_left.html#Directionality
Select the paragraph (e.g. using triple click) and use the button for right-to-left direction (¶◀) in the Paragraph section of the Start pane.
As Hossein’s answer explains, the issue is the directionality in the paragraph. It changes to left to right when you insert a Latin letter, and you need to fix this manually.
You need to add an invisible RLE Unicode Character at the start of the line [^].
It's : 0x202B hex = 8235 decimal or RIGHT-TO-LEFT EMBEDDING (RLE).
It's necessary for Notepad but MS-Word is able to handle it. you need to right align your text correctly.
How to enter RLE: http://www.fileformat.info/tip/microsoft/enter_unicode.htm
In word processing, you have a main text direction which is either left-to-right or right-to-left (or top to bottom, but let's ignore that :-), and you have a text direction for individual characters, which will also be left to right or right to left.
The word processor splits the text into chunks of strings with the same character ordering, then displays these chunks according to the main text ordering.
It seems that your main text ordering was left to right. As long as all your text is arabic, there is just one chunk with arabic text. You see already it is displayed left aligned and not right aligned because the text ordering is left to right. The characters are displayed right to left because that is how arabic is displayed.
When you inserted latin text, you had three chunks: Arabic, latin, arabic. These three chunks are displayed left to right because that is the main text ordering. That would be fine for text that is mostly latin (like "The arabic words for dog and cow are ... and ..."). For text that is mostly arabic with the occasional latin word, you need to change the main text ordering to "right to left".
Just follow this:
Copy and paste the arabic text into from word or text document to ADOBE Illustrator.
Save the illustrator document as in .EPS format.
Open indesign and place the .EPS document into the place you want.
Since indesign can't handle arabic text issue by it self, this method will help many designers.