News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

64-bit DirectX 11 - Part 4 - Color Fonts

Started by aw27, October 20, 2018, 07:36:49 PM

Previous topic - Next topic

aw27

This is the MASM source code and .exe for the Direct2D application.
As mentioned in the first example, dxMain.inc is saved as UTF-8 (without BOM), so make sure you use an editor able to read it. Even with a suitable editor you may not be able to see all characters properly (in Windows 10. In Windows 8.1 you will not see them all no matter what you do) unless you use the Segoe UI Emoji font on the editor (except for VS 2017 in Windows 10, which makes some sort of miracle and allows us to see all characters with any font, amazing).






aw27

If we export the Segoe Ui Emoji font from Windows 10 to Windows 8.1 there are 2 little guys at the bottom that do not render.  :(


TimoVJL

#17
So Direct2D use only installed font, not the font added with AddFontResourceEx() function :(
I also verified that with with ProcMon.

EDIT: Custom Font Collections (Windows 7/8)
May the source be with you

felipe

Nice work  :t, i think i have exactly the same output result as mabdelouahab...But don't worry about it aw, i don't think i will install some extra fonts... :idea:
Thanks for sharing your work... :greenclp:

aw27

#19
@Timo,

May be will not work, AddFontResourceEx is a GDI function.  :idea:

Later: I tested AddFontResource, it works in Windows 10, does not work in Windows 8.1.

@Felipe

I am not afraid, I am doing tests on a virtual machine. If things go wrong I will look for a backup snapshot.  :biggrin:

TimoVJL

#20
Example for Windows 7 to use Segoe UI Emoji 1.12 or 1.20 from local file;)
Support only one font file.

EDIT: Example just read SEGUIEMJ.TTF font from current folder. Without installation, as otherwise font come from font cache.
So this program don't work in Windows 8.1 or Windows 10, as thoseversions have that font already. (1.02/1.20)
EDIT: updated Segoe UI emoji font
May the source be with you

jj2007


aw27

I made some experiments with RichEdit version 8.5 (the one that seats in the System folder of Windows 10 under msftedit.dll), trying to make some sense of Murray Sargeant blogs - I have never seen any source code produced by him he is just a talkative person!  ::)
In several points he appeared to say that the most recent RichEdits support D2D/DWrite. But they do not  ::), what does that is the "windowless" version or in tablets or Windows Phone (Microsoft does not know that almost nobody uses Microsoft tablets and phones).
Since I have never found anyone interested in windowless RichEdit as well, I subclassed a RichEdit and shot the emoticons to it as a revenge!  :P



And also in Windows 7 after giving it some color (in Windows 7 the RichEdit version for msftedit.dll is 4.1).


It is about time Microsoft makes some really innovative work on RichEdit.

jj2007

Quote from: TimoVJL on October 26, 2018, 04:14:56 PM
Example for Windows 7 to use Segoe UI Emoji 1.12 or 1.20 from local file;)

Thanks a lot, Timo, for the PM on how to install the font on Win7-64 - it worked like a charm :t

Demo attached. The text of the lower (RichEdit) control can be zoomed holding Ctrl and moving the mousewheel.

GuiParas equ "Emojis demo", x100, y20, w1000, h220, cRed, b00FFFFD0h
include \masm32\MasmBasic\Res\MbGui.asm
  MakeFont hEmojis, Height:-24, "Segoe UI Emoji"
  GuiControl MyEdit, "edit", h500, res:99, font hEmojis         ; use resource #99 as text
  GuiControl MyRich, "richedit", y500, h500, res:99, font hEmojis, bcol RgbCol(222, 255, 255)
GuiEnd

TimoVJL

@jj2007
With AddFontResource[Ex] and RemoveFontResource[Ex] you can use font without installing font.

The example was for using font without installing it.
May the source be with you

jj2007

Quote from: TimoVJL on October 27, 2018, 05:37:22 PMWith AddFontResource[Ex] and RemoveFontResource[Ex] you can use font without installing font.
Good to know, thanks. AddFontMemResourceEx would be even more interesting then, but of course, it implies that you ship a very bloated exe, about 1MB.

TimoVJL

#26
A puzzle, what are those IIDs:[3880] IDWriteFontFileEnumerator QueryInterface
[3880]  riid = {0x487F87BB,0x7CF5,0x4100,0xA6,0x0C,0x34,0xC0,0x3A,0xDC,0x0A,0x80};
[3880] IDWriteFontFileStream QueryInterface
[3880]  riid = {0xBE48BF93,0xB782,0x4EA5,0xBA,0x3E,0xF1,0x8A,0xB6,0xC9,0x51,0xE0};
Font loader don't work with TwemojiMozilla.ttf / 'Twemoji Mozilla'. That font come with Firefox.
May the source be with you

aw27

The attachment contains an .rtf file with some emoticons which render in color in Word 2016 (but don't in Wordpad).
I believe Word technology is based on the RichEdit control and according to Murray Sargeant using TxDrawD2D is the key to render the color fonts to the fkng RichEdit. Sure, nobody ever explained how to do it although somewhere it is mentioned that it should work on the windowless RichEdit. As expected, there is no samples as well for the windowless RichEdit, although after much digging I found a 16 year old example of a windowless RichEdit by some guy called Yves Maurer (I think this is the original source but am not sure ).
It was quite outdated, as expected, but was a starting point. It took me a few hours to figure how to get the ITextServices2 interface and make TxDrawD2D  work. All right it worked but could not display the .rtf the same way as Word 2016 does, it show as Wordpad does.
At this point, I am not going to pursue my investigations because have already spend a lot of time with this matter.   :shock:


TimoVJL

ITextHost Class
QuoteYou must implement the ITextHost interface before you call the CreateTextServices function.
May the source be with you

aw27

Right, this is done in the Yves Maurer sample.
However, I had to modify that part as follows:

typedef HRESULT(STDAPICALLTYPE * CreateTextServicesProc)(
   IUnknown *punkOuter,
   ITextHost *pITextHost,
   IUnknown **ppUnk);


HRESULT CFormattedTextDraw::CreateTextServicesObject()
{
   HRESULT hr;
   IUnknown *spUnk;

   HMODULE hmodRichEdit = LoadLibraryW(L"msftedit.dll");
   CreateTextServicesProc CreateTextServices = (CreateTextServicesProc)GetProcAddress(hmodRichEdit, "CreateTextServices");


   hr = CreateTextServices(NULL, static_cast<ITextHost*>(this), &spUnk);
   IID* pIID_ITS = (IID*)(VOID*)GetProcAddress(hmodRichEdit, "IID_ITextServices2");


   if (hr == S_OK) {
      hr = spUnk->QueryInterface(*pIID_ITS, (void**)&m_spTextServices2);
      hr = spUnk->QueryInterface(IID_ITextDocument, (void**)&m_spTextDocument);
      spUnk->Release();
   }
   return hr;
}