MS Word - fomat a Content Control with bullet points - ms-word

I'm working with Content Controls in MS Word 2010. I add text to the Content Controls using Java. Some of the text contains several sentences and I would like to see each sentence appear as a bullet point. I've managed to define a bullet point style in MS Word. However, I don't know how to make each sentence appear as a bullet point (now the entire text appears as just one bullet point). What is the best way of going about this? I'm considering using VBA but am not sure how to add a VBA macro to a Content Control.

In Word, bullet points are implemented via list numbering.
For list numbering, you need paragraphs (you set the numPr on the pPr).
For a content control to contain paragraphs, you need a block level content control.
So, you need a block level rich text content control, then put your content in it, one paragraph per sentence, formatted using your list numbering (either directly applying the numPr, or a style which uses that numPr).

Related

Dynamically create textbox rotated by 180 degrees

I would like to create a Word document with multiple text boxes that serve as name badges. Each name appears twice, once set normally and once rotated by 180 degrees. Later, they are printed on paper, cut and folded, so they can stand on a table.
I am using docx4j to generate the DOCX file. My idea is to have a fragment in one Word file that serves as a template for a single name badge. I'd like to load that template and fill the placeholders with real names. Multiple fragments are then concatenated and written to a second Word template, so ultimately I have a list with multiple name badges. The paper I use allows two name badges on each page (i.e. four text boxes).
However, I fail implementing this with docxj4. This is what I tried:
(1) First, I tried filling a single name badge. The placeholders got filled correctly, but the rotated text box of my Word template (input) became an ordinary (not rotated) text box in the output file.
(2) I also tried MainDocumentPart#addParagraph(String) and created the entire paragraph myself, using XML code generated in Word (where the text box was rotated). The output generated by docx4j, however, again did not respect the rotation. It created two text boxes, but when I view them in Word now, I even cannot rotate them there anymore. It seems like the generated text boxes are different from those created by Word in the first place.
Long story short, how can I create a rotated text box with docx4j?
It would be very convenient, if I could have a Word template to layout the name badges, but if I would have to create the entire thing programatically, it would be fine, too. Also, other ways of rotating text would be okay for me. But it seems like text boxes are the only objects in Word that can actually be rotated by 180 degrees.

GitHub readme markdown to include bullet points inside of table

I am trying to put bullet points inside of a GitHub text box for the READme.
I know how to do them separately. For example to create the gray textbox I can do:
```
item1
item2
```
To create bullet points I can do:
* item1
* item2
However if I try and place the bullet points inside of the table, the literal syntax for the bullet points shows up, rather than the bullet points. I have tried escaping the bullet point characters.
How do I get bullet points inside of the table?
The GitHub Flavored Markdown Spec plainly states:
Block-level elements cannot be inserted in a table.
Of course, lists are block-level elements, and therefore they cannot be inserted in a table.
Generally the way to get around such restrictions in Markdown is to use raw HTML. However, a raw HTML list would be a HTML block, which is also a block-level element and not allowed in a table. Therefore, you would need to use raw HTML for the entire table.

How can I use the DocX library to change the font globally, remove superfluous spaces, and remove or add extra line breaks?

I want to, using the DocX library [https://docx.codeplex.com/], convert a .docx document to use a different font. Does anybody know how to do that? The samples projects are very spare, and the documentation is nonexistent.
I find, too, that often there are extraneous spaces in documents, and I want to iterate over all these until there are never two contiguous spaces. I can do this in a loop, I guess, replacing " " (2 spaces) with " " (1 space) until " " (2 spaces) is no longer found.
However, I also want to remove superfluous line breaks that sometimes occur when copying-and-pasting text into a document. I can do it "manually" (in Libre Office, not sure how it's done in MS Word), as I got an answer to this question:
(select "Regular Expressions" and then replace "$" (without the quotes) with a space)
...but how programmatically, with DocX?
Additionally, in some cases I want to ADD line breaks/"paragraph returns" where there are legitimate line breaks between the end of one paragraph and the start of another, but no extra line to separate them visually. According to this:
...I can add a paragraph/line break to a legitimate line break by searching for "$" and replacing that with "\n\n"
This does work, too (manually, in Libre Office); but again...how to do this with the DocX library?
It appears that not all of this is possible with the current version of the DocX library you are using. If it is not exposed in documentation, the functions might as well not exist, and you should not be using undocumented features.
There is a much more mature library available, however, called the "Open XML SDK", that can do everything you need.
The correct way to change a font, regardless of whether you are doing it with the document editor, or you are writing a program to manipulate these files, is to change the appropriate text's style attribute, or changing the definition of style in use.
You should never, ever, ever, ever directly change the font of any text. Personally, I think that the 'font type' and 'font size' menus should be removed entirely from word/libreoffice/etc, and only be accessible inside a 'change style properties' dialog; the only reason to directly apply a font is if you are actually providing an example of particular typeface under discussion!
See How to: Replace the styles parts in a word processing document (Open XML SDK) from the MSDN documentation for a description of the way that works.
To search and replace text, the applicable MSDN page is How to: Search and replace text in a document part (Open XML SDK). For specifically replacing multiple spaces with a single space, there are numerous results on Google that should all work to at least some degree.

What does it mean for a CTLine to have "string access"?

I'm trying to solve a hairy problem with UILabel, and I've gotten most of it figured out, except for one thing: I'm having a challenge understanding what it means for a CTLine to have "string access".
The method that I'd like to use is CTLineGetOffsetForStringIndex. Here's a link to the documentation for the method.
Here's the part of the documentation that I don't understand (emphasis is mine):
The primary offset along the baseline for charIndex, or 0.0 if the
line does not support string access.
When I'm running this method, I'm getting 0.0 back, so I guess that means the line doesn't support string access - but what does that mean, exactly?
The statement "the line does not support string access" may be inferred as meaning that the line of text may not be treated as a sequence of characters that may be accessed by the index of each character.
This may open up a large discussion about visual characters versus non-visual characters, and glyphs versus characters. But to simplify the discussion, assume that a line of text may have one of the following states:
more than zero characters (characters which translate to either glyphs or whitespace within the same line) are present in the line of text in question
there are no characters in the line of text which occupy any "space"
Now to provide some rationale for this inference.
Apple's documentation provides a description of Text Kit, upon which UILabel is built:
The UIKit framework includes several classes whose purpose is to display text in an app’s user interface: UITextView, UITextField, and UILabel, as described in Displaying Text Content in iOS. Text views, created from the UITextView class, are meant to display large amounts of text. Underlying UITextView is a powerful layout engine called Text Kit. If you need to customize the layout process or you need to intervene in that behavior, you can use Text Kit. For smaller amounts of text and special needs requiring custom solutions, you can use alternative, lower-level technologies, as described in Lower Level Text-Handling Technologies.
Text Kit is a set of classes and protocols in the UIKit framework providing high-quality typographical services that enable apps to store, lay out, and display text with all the characteristics of fine typesetting, such as kerning, ligatures, line breaking, and justification. Text Kit is built on top of Core Text, so it provides the same speed and power. UITextView is fully integrated with Text Kit; it provides editing and display capabilities that enable users to input text, specify formatting attributes, and view the results. The other Text Kit classes provide text storage and layout capabilities. Figure 8-1 shows the position of Text Kit among other iOS text and graphics frameworks.
Figure 8-1 Text Kit Framework Position
Text Kit gives you complete control over text rendering in user interface elements. In addition to UITextView, UITextField and UILabel are built on top of Text Kit, and it seamlessly integrates with animations, UICollectionView and UITableView. Text Kit is designed with a fully extensible object-oriented architecture that supports subclassing, delegation, and a thorough set of notifications enabling deep customization.
The answer to the related question mentions several classes such as NSTextStorage, NSLayoutManager, and NSTextContainer.
Consider that the UILabel uses all the above classes to provide the end result of displaying text in the parent UIView, which the end user sees on the screen. A layout manager (an instance of NSLayoutManager) coordinates data flow between the text view, the text container, and the text storage, resulting in the display of characters in the view. The layout manager maps the characters to glyphs, and figures out which lines to use to lay out the glyphs. The layout manager also figures out how to display things like underline and strikethrough, which are not part of the glyphs.
Important to this discussion is the fact that the Layout Manager lays out lines of text. If that line of text is selectable, the user may select visible characters in the line. In this particular case, there is "string access" for the line.
A similar concept is the method posted in the solution to related question:
func boundingRect(forGlyphRange glyphRange: NSRange, in container: NSTextContainer) -> CGRect
Returns a single bounding rectangle (in container coordinates) enclosing all glyphs and other marks drawn in the given text container for the given glyph range, including glyphs that draw outside their line fragment rectangles and text attributes such as underlining.
Finally, the reference discussion for the function CTLineGetOffsetForStringIndex speaks about graphical offsets which are suitable for drawing custom carets. The carets may be used to show insertion points or text selection. The primary and secondary offsets may be thought of as beginning and end indices for a string -- a sequence of characters. If there is no sequence of characters for a given line, there can be no selected characters, no carets, no range of glyphs. Therefore no "string access".

Only display one paragraph of text

You can set what the Facebook Share preview says. I would like it to be the first paragraph of my movable type entry. The people who make entries sometimes use
<p>
tags or they use the rich editor which puts in two
<br /><br />
tags to separate paragraphs.
Is there a way I can have movable type detect when the first paragraph end and only display the first paragraph? I would like to add that to my entry template so it will add some information to my head.
EntryBody has a lot of attributes to help format the output of the tag. You can use those to change the content so it shows up correctly in HTML, JavaScript, PHP, XML or other forms of output.
If you understand how to use regular expressions, you can use that and an additional language, say PHP, to break the body up into an array and only output the first paragraph or element of the array.
The simplest thing, though, I would think, would be to do something like
<mt:EntryBody words=100>
That will cut off the entry body after the first 100 words. You could also require users to upload an excerpt with the entry and use the entry excerpt for Facebook, instead.