I'm rendering text in Direct2D/DirectWrite, but calling SetLineSpacing() on either TextFormat or TextLayout seems to have no effect. Does anyone know why?
I'm 99% sure that this is a bug. I have done a little playing around with Direct2D lately and also had a problem with SetLineSpacing() on TextLayout, think it is the same as what you are describing, in that case I can confirm that it's not just you. Reopen your bug report on MS Connect, it has been closed.
I even have the same problem as Dmitri Nesteruk said.
However, I find out that if you set the lineSpacing "after
CreateTextLayout", SetLineSpacing cannot work.
Otherwise, if you set LineSpacing before CreateTextLayout,
it can work now.
Maybe you can try this soluton.
PS: My env. is in Window Vista SP2.
Many thanks.
Unfortunately you don't provide code showing what you're trying to do. I'm assuming that you're trying to set the line spacing like this:
pTextLayout->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, lineSpacing, baseline);
The documentation on MSDN is not terribly clear about the different line spacing methods. The default method causes the spacing for each line to be derived from the used font and inline objects, if any, so each line is the height that it needs to be according to its content. In this case, the two parameters, lineSpacing and baseline, are ignored.
If you have a text format that uses a single font (and font size) and no inline objects (or inline objects that are no higher than the text), you can specify uniform line spacing. This is what the DWRITE_LINE_SPACING_METHOD_UNIFORM is for. I've just tried it and calling SetLineSpacing() with this method results in uniform line spacing according to the passed arguments.
Starting with Windows 10, there is a third line spacing method, DWRITE_LINE_SPACING_METHOD_PROPORTIONAL, that can be used to achieve line spacing that is relative to what the font sizes and inline objects specify. However, this is only supported on Windows 10.
The most misleading part, in my experience, is that calling SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, x, y) succeeds without an error, and retrieving the line spacing parameters afterwards, using the GetLineSpacing() method, returns the values that were provided (while they still don't achieve anything). The API is internally consistent in this regard, not discarding the specified values even though they don't achieve anything useful. Also, when you call GetLineSpacing() on a newly-created IDWriteTextFormat or IDWriteTextLayout instance, the values are returned as zero (which is correct because the line spacing method is DWRITE_LINE_SPACING_METHOD_DEFAULT). In order to be able to do anything useful, you have to determine the default line spacing for the font you're using. You can achieve this by calling IDWriteFont::GetMetrics() on the font you're using. The default line spacing is the sum of the ascent, descent and lineGap values.
Charles Petzold wrote about this in an article about Pagination With DirectWrite.
Am i missing something?
Neither IDWriteTextFormat nor IDWriteTextLayout has a SetLineHeight function ...
Have you checked the HRESULT error code returned by SetLineSpacing()?
Hint: If you're using Visual Studio just type eax,hr in one of the debug Watch windows to see any possible error code right after the call.
Source
minimum supported client: Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista.
Do you run any of the above stated versions of windows?
I believe the reason why you aren't seeing any changes is because any version below the ones states above doesn't support the SetLineSpacing() in DirectWrite.
Related
(I've looked far and wide but I can't even find anyone having the same problem, not to mention a fix or anything. Closest is this thread which just announces the feature...)
The way it currently works for me, the VS2019 code lens integration of P4VS (for C++ at least) is almost completely pointless. Each function has an indicator added, but the information in each is identical - namely the change history of the entire file:
According to this Microsoft article, I would expect to either get function-level change information that pertains only to that function or a single change summary of the file at the bottom of the editor. But instead I get the worst combination of both.
I'm mainly surprised that I can't find anyone else talking about this, so I assume something is misconfigured on my part. Can't find anything in the configuration options though...
Is this just a bad implementation by Perforce or is something wrong on my end?
I have just found out that it can be turned off by Visual Studio options.
How to turn off CodeLens-References
Text Editor > All Languagues > CodeLens
I need to convert some text-to-bitmap rendering routines in existing C++ code that is using GDI and GDI+ to use DirectWrite (CFF support and OTF-feature support required).
I'm new to DirectWrite. Spending some time on research on what's required for the migration of existing functionality and doing some prototyping, I encountered an issue:
My problem is that DirectWrite (out of the box) doesn't support character spacing adjustment (which is a requirement for the existing app), at least not on Windows 7. I know it comes with Windows 8, but another requirement for this existing app is to run on Windows 7, unfortunately.
What I found in my research so far is that the way to go seems to implement a custom DirectWrite Text Layout, but I haven't found any good guideline on how to do this, especially in regards for character spacing (the documentation/examples on MSDN in regards of how to create a custom Text Layout are a little vague for my taste).
As I figure this must have been done before, before spending days and/or weeks of research and developement on re-inventing the wheel, does anybody here know a sample implementation of a DirectWrite text layout with custom character spacing I could use as a starting point or tutorial?
UPDATE1: Not an answer but - I found out that the IDWriteTextLayout1 interface (which supports setting the Character spaces) not only comes with Windows 8, but also with "Windows 7 Platform Update for SP1" (KB 2670838) on Windows 7. as I can require that for out app to run properly, this solves my issue, although it doesn't answer my question.
A custom layout is pretty complex due to bidi and line wrapping and the need to call the lower level API's, but a sample is here [https://msdn.microsoft.com/en-us/library/windows/desktop/dd941711(v=vs.85).aspx]. As for character spacing, once you have the array of glyph advances back from the shaping process (IDWriteTextAnalyzer::GetGlyphs), just add a delta onto all the advances. In the linked SDK sample, you would add a for loop inside FlowLayout::ShapeGlyphRuns so that it happens before line wrapping and drawing.
STDMETHODIMP FlowLayout::ShapeGlyphRuns(IDWriteTextAnalyzer* textAnalyzer)
{
...
hr = ShapeGlyphRun(textAnalyzer, runIndex, glyphStart);
...
// Add additional character spacing to each trailing edge of each glyph.
for (auto& advance : glyphAdvances_)
{
advance += 5.0f;
}
...
}
Note an API ApplyCharacterSpacing was also added to Windows 8 which is more robust than adding it manually yourself because it considers more complex scripts with multiple glyphs per cluster (but of course if you have that API, then you also already have IDWriteTextLayout::SetCharacterSpacing).
Title says pretty much everything. Once upon a time when I was under 13, my older bro did in BorlandPascal a thing which amazed me. He defined kind of table [8][8] with values of 1 and 0, meaning respectively foreground and background. Having several of such tables he could somehow redefine default ASCII characters to look like in these tables. I have no idea how it was done, but it worked.
My question is: can I do similar thing in ncurses, and if I can then how to do it?
The short answer is no. What ncurses does is generating ANSI escape codes which are interpreted by the terminal. There are no codes for altering the font. (Althou there have been extensions propesed no commonly used terminal supports them, neither does ncurses.) And there is no generic way of communicating with the terminal through some kind of side channel for changing the font. But there might ways in some specific situations.
If you have direct access to a Linux console for example you could could do all sorts of things, much like in Borland Pascal. But it will likely be more messy and less impressive.
As the selected answer explains, this is not possible for NCurses to render custom glyphs. ncurses only manipulates the terminal screen state via escape codes (Clearing and rewriting lines to achieve interactivity).
However it should be noted that's very possible to use custom glyphs in the terminal via custom fonts.
This is what Powerline does (a popular terminal UI status line for vim, tmux and friends): https://github.com/powerline/fonts
By patching the fonts, you can inject your glyphs into the existing font being used by the terminal, which then you can access and render via ncurses as any other character.
Of course this is not ideal solution, but with some auto patching of the fonts, and careful testing, it makes it possible to build an app that uses custom glyphs—when your really in a pinch for more expressive UI tools than ncurses can offer.
Further reading: https://apw-bash-settings.readthedocs.io/en/latest/fontpatching.html
I am trying to write a C++ program where the screen updates every 1 second. However, I want the screen to be similar to htop, where it updates and does not have to scroll with each update. That way, I don't have a step-by-step iteration in my terminal.
Does anyone know what this style is called or how to program it?
Thanks!
The usual way is with something like ncurses. If you're on Windows, it has console functions built in so you can do the same without any extra libraries (though they do take a while to understand). If you only want one line of output, you can use a '\r' to return to the beginning of the current line and/or \b to backspace over previous characters (handy if yoy only want to overwrite a few little bits and pieces).
You'll need a library like curses (on *nix) or pdcurses for Windows (conio functions would probably still work on windows).
I'd like to get the current (possibly uncommitted) text out of the formula bar in Excel (from an addin in-process). All "usual" techniques don't work, like GetWindowText(...), etc.
As for cursor position:
GetCaretPos actually works (returns the x,y coords of the caret), but EM_CHARFROMPOS doesn't (always returns 0) so that's a dead end.
Is this functionality exposed through COM or to the XLL API in any way?
EDIT: I'd also like to point out that I think the majority of my issues come from the fact that the formula bar is (at least I'm 99% sure) NOT an edit control, which can be seen by looking at its window class.
The formula bar, and indeed most of the controls in Office are non-standard. Sending standard messages will not yield success.
I imagine the only option will be to reverse-engineer the executable code.
SteveN, which version of Excel ?
The control will be a window. Office 2010 is 'nicer' in this respect, using more standard controls.
You could use Spy to watch all the messages that get sent to that control and try mimicking those to see what you get. Long road though.