I am just working my way through DirectWrite in C++ which appears to be solving my demands for having equal layouts in different render targets (screen and printer).
I have closely inspected the HelloWorld sample (http://msdn.microsoft.com/en-us/library/windows/desktop/dd368048%28v=vs.85%29.aspx) and already learned a lot from that.
The HelloWorld example was even topped (my opinion) by an article from Charles Petzold which was throwing much more light on advanced features of DirectWrite: "Character Formatting Extensions with DirectWrite" (http://www.charlespetzold.com/blog/2014/01/Character-Formatting-Extensions-with-DirectWrite.html).
But there is still one subject missing in all the documentation and examples I found so far: The documentation about use of TABstops in DirectWrite. All I found so far is a (very) short documentation about setting of "incremental tabs" which does not even mention how the text in each individual tab can be aligned.
Does anybody know about a more in-depth description about TABs in DirectWrite?
Thanks in advance.
Sounds like you're thinking Word degree of complexity tab stops with individual widths and alignment for each tab - IDWriteTextLayout supports uniform tab spacing where each tab is a multiple of a distance set by SetIncrementalTabStop. If you need to lay out several unique layouts with distinct distances and alignments, you'll need to create one IDWriteTextLayout per column. Tabs are convenient, but they aren't best for tables.
Related
In Sublime Text, if you hold control while clicking, you can add another cursor to the document, allowing you to type and edit in multiple places at once. I'm trying to recreate this with Qt's QPlainTextEdit. The logic seems pretty simple...
On Ctrl+click, create and store a new cursor at location of the click
Draw all cursors
When any key events happen, make sure the other cursors also receive them
However, it seems that in order to do these things, I have to understand exactly how QPlainTextEdit works, and while I have a loose understanding, I find the source to be very dense and difficult to navigate.
While this feature is very important to me, I can't afford to spend a month on it. I don't know how to reasonably proceed. Is there some open source text editor built with Qt that has this feature? Can I in fact implement it without thoroughly understanding how QPlainTextEdit works? Is there some other solution I have not considered? I thought this would be trivial, or at the very least someone might have solved it before, but that doesn't appear to be the case. Any advice is appreciated.
Is there some open source text editor built with Qt that has this feature?
QtCreator is open-source (source code) and has partial multiple-cursor functionality. While it does not support Ctrl+Click to add a new cursor, you can do Shift+Alt+DownArrow to add a cursor to the following line (same column), like in SublimeText, and then insert text to all the lines at once.
It seems implemented in their class TextEditorWidget, which inherits QPlainTextEdit and reimplements plenty of its virtual methods. I don't exactly know how they implemented the multi-cursor functionality, but probably looking at the code of TextEditorWidget can give hints.
However, keep in mind that QtCreator does not have full multi-cursor functionality like in Sublime Text or CLion: the mutliple cursors are necessarily in the same column, and you cannot move the multiple cursors left/right. For example something I often do in Sublime is multiple selection at the beginning of lines, followed by Ctrl+RightArrow to jump all cursors "one word to the right". You cannot do that in QtCreator as of August 2020.
There is an open feature request for having true multiple-cursor functionality in QtCreator:
https://bugreports.qt.io/browse/QTCREATORBUG-16013
However, it seems that in order to do these things, I have to
understand exactly how QPlainTextEdit works, and while I have a loose
understanding, I find the source to be very dense and difficult to
navigate.
To some extent, but not a lot. Once you get the cursor positions, you know the positions in the document where text needs to be inserted. QTextEdit already supports multiple cursor positions:
https://doc.qt.io/qt-5/richtext-cursor.html
Rich text documents can have multiple cursors associated with them,
and each of these contains information about their position in the
document and any selections that they may hold. This cursor-based
paradigm makes common operations, such as cutting and pasting text,
simple to implement programmatically, yet it also allows more complex
editing operations to be performed on the document.
and
Multiple Cursors
Multiple cursors can be used to simultaneously edit the same document,
although only one will be visible to the user in a QTextEdit widget.
The QTextDocument ensures that each cursor writes text correctly and
does not interfere with any of the others.
Since this feature already exists, it may not be as difficult as thought to read the documentation and implement the feature.
As QPlainTextEdit is implemented by using most of the tech behind QTextEdit and QTextDocument, maybe it will meet your requirements.
I have a Django Project where I used Sphinx to create my documentation. I went through sphinx-apidoc and ran 'make latexpdf'. The resulting documentation has a quite a few lines that flow out of the margin. On top of margin issues, lines in the index start overflowing onto each other.
Overflowing Lines
Margin Issues :(
Is there an easy way to fix these issues (or an easier way to create PDF documentation)?
ELI5 if possible (I'm not well-versed in LaTeX)
The overflowing lines situation in the index should improve from adding this to conf.py:
latex_elements = {
'printindex': '\\footnotesize\\raggedright\\printindex',
}
Or, you can switch to Japanese language which does something like that (even better) out-of-the box from its special document class ;-)
TeX does not always know how by itself how to insert linebreaks: after all it is good at hyphenation of natural language. But as pointed out in comments Sphinx coerces LaTeX into handling better long code lines since 1.4.2.
Since recent 1.5.3, user can customize page margins, check http://www.sphinx-doc.org/en/stable/latex.html#the-sphinx-latex-style-package-options for documentation of hmargin and vmargin which can be configured via 'sphinxsetup'.
Once upon a time I read in some book on an interesting idea of of Source code syntax visualization: they did not use colors like any (average) text editor nowadays does. Instead they tried to format the code like text in a book, thus: using different fonts, font sizes, boxes, bars, indentation etc. The code revealed its task in the way it was formatted, not as it was colored.
A function was basically a new section's headline in large font size (maybe underlined), the argument variables that followed were a dotted list (the example was Pascal code) - or a grey box or something. Loops might had boxes around etc. I can't remember the details, but you might get the idea.
I can not find any trace of projects that tried this again, maybe the benefit was not evident enough or the effort to implement it in some editor was too high (admittedly, it is easier to just use some different color for the same courier font).
But I am still interested whether anybody knows what happened to that idea and these projects or implementations. If you had a parse tree generator front end for a distinct programming language, say, C++, and an engine that generates this pretty printed output from a parse tree (could be done with LaTeX, probably), it might be easy to create some nicely readable code documentation just in black-white.
Edit: an example, basically taken from the TinyXml library.
The code with some common syntax highlighting using colors and a bit italic, underline would look like:
might be, just using grayscale elements like:
There is a Visual Studio extension called TextHighlighterExtension. It was mainly a text colour formatter, but it could be configured with a lot of customisation to change the font type and size as well. This had a couple of defaults where 'class' and 'interface' was increased in size, for example.
I know of other extensions that are similar, if limited in scope - for example, the "I hate regions" extension that appears to fit your question well, or the CodeBubbles concept.
I'm looking for an open source (or cheap commercial) library that handles the difficulty of formatting information for standard label paper (say Avery 5160) for example. I would like to use the library in a Mac and iPhone app. I saw this similar question for a dedicated label printer, but I am looking for a Mac compatible library that will work with label paper loaded into any printer:
What options are available to developers for printing to a dedicated label printer?
Alternatively, I'm interested in suggestions about my best strategy for doing it myself... I'm not up for figuring out the intricacies of many different paper formats - I would probably target just one kind of US Letter label paper and one kind of A4 label paper. Which are the most popular?
Having written a (closed source) Mac codebase that actually does this, I can tell you that it's not the most difficult thing in the world. My codebase only supports Avery labels. I have a resource file in the app with geometry info for each kind of label (number of rows, columns, margin sizes, gutter sizes, etc.). I use this to layout a grids of properly sized subviews of the main print view, where each subview is one label. Each subview is responsible for modifying the layout of its information to fit its size. Conceivably this could be done using Cocoa Autolayout now (my code predates Autolayout).
You can download a CSV version of my label dimensions file here.
EDIT: I might also mention that you'll need to do some significant extra work for a solution that works on both Mac and iOS. The printing APIs are quite different between the two platforms. Even if you use a custom view to do printing on iOS, UIView and NSView aren't exactly the same. Still, with some careful planning, you should be able to come up with something that at least shares common core code on both platforms.
I am writing a windows program (no mfc) and need to output a status line to the operator every few seconds or so. I tried using rich text boxes but after so many hours it seems to hang up. Does anybody have an suggestions on what I can use instead?
People mentioned that my buffers might have been exhausted. I thought I had planned for that. After I had about 1000 lines displayed I would take the first 500 and remove them using the select and cut options in rich text boxes. I still ran into the same problem.
This question appears relevant, and this one too. But they don't give any concrete recommendations for an alternative to rich text boxes.
You might try the Scintilla control (scintilla.org) which does not appear to have any hard limitations on text size. It has a permissive license. It is used by many text editors such as Notepad++, Notepad2, Code::Blocks, FlashDevelop. I haven't tried it personally but there from the documentation it looks easy to use it in a Windows API application. Of course, it might be overkill for your purposes.
If you keep appending to the text in the control every few seconds for hours then you are probably running into some memory constraint on the control or the process. I think you would have this problem with any control you choose given update frequence and how long you're running the program.
Have you considered implementing a simple circular buffer for the content of the text box? Say only keep the last hour's messages. You could maintain a separate log file for history if the operator needed to go back in time for hours.
I ended up writing my own control to do this, essentially duplicating the Output window in Visual Studio. It was a success, but it ended up being much more code than I thought it would be when I started - I insisted on features such as auto-scrolling when the cursor was on the last line, select/copy, bold text, etc. It was backed by a std::deque so I could limit the number of lines stored for the window.
Unfortunately the code belongs to a former employer so I can't share it here.