The MASM Forum

Projects => Game Development => Topic started by: AW on October 20, 2018, 07:36:49 PM

Title: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 20, 2018, 07:36:49 PM
Color Fonts (https://docs.microsoft.com/en-us/windows/desktop/directwrite/color-fonts) are appearing everywhere but knowledge about them is not widespread. One way of rendering them is using Direct2D. Since I had previously done some work on Direct2D I made some changes to the posted sample.

(https://www.dropbox.com/s/b07vn3ytc4owv5x/emoticons.jpg?dl=1)

You will need Windows 10 (I think Windows 8.1 is enough but did not confirm) and full support for DirectX 11 in your system, including the DX11 SDK because all the LIBs are there.

Lots of color unicode color characters. (http://xahlee.info/comp/unicode_index.html)

Note:
dxMain is saved as UTF-8, make sure your editor can retrieve it.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: hutch-- on October 20, 2018, 08:00:33 PM
Jose,

Will you build the EXE as well, I don't have that DX library.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 20, 2018, 08:06:42 PM
Hutch,
The .exe is there as well, dx11_64ColorEmodjis.exe  :biggrin:
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: hutch-- on October 20, 2018, 10:08:55 PM
The animation looks good, if you really want to nitpick, the rotating block has its horizon line the wrong way around when it is at the front of the center block. Nice work  :t
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 20, 2018, 10:25:18 PM
Windows 8.1
EDIT: updated Segoe UI emoji font (https://support.microsoft.com/en-gb/help/4011155/august-7-2018-update-for-office-2013-kb4011155)
EDIT: a small Direct2D example for Windows 8.1 ->. Only a that happy emoji line and only for PellesC 9, as \Uxxxxxxxx can be a problem with others.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: mabdelouahab on October 20, 2018, 11:29:35 PM
 :(
Quote
Direct3D Initialization failed
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 21, 2018, 01:02:40 AM
@Hutch,
Well spotted (it helps being a photographer also).  :bgrin:

@Timo,
Yeah, I have included Unicode version 8,9 and 10 characters which are not recognized in Windows 8.1  :(

@mabdelouahab
It is a bit demanding in hardware, I have the same problem if testing from a virtual machine.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: felipe on October 21, 2018, 04:30:05 AM
Looks like another good work  :icon14:, unfortunately i got the direct3d initialization failed probably because i have not installed anything related to directx 11... :redface:
Thanks for sharing...  :t
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 21, 2018, 04:12:53 PM
@Felipe
Direct2D/DirectWrite can't be used directly with D3D 11. Yes, it is the way Microsoft recommends to write text but it needs to be used with a D3D 10.1 device and swap when rendering. I believe this is the root of the problems. When I can I will see if I can make a simpler text writing example not involving D3D.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: mabdelouahab on October 21, 2018, 05:16:04 PM
@mabdelouahab
It is a bit demanding in hardware, I have the same problem if testing from a virtual machine.
I don't think so.
This is a test of D3D11 / hardware (windows 8.1 x64)
(http://gdurl.com/Lx-X)
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 21, 2018, 10:49:28 PM
Many notebooks have 2 graphics cards in order to save energy with a low-end graphics card good enough for most tasks, and you will have to run the Nvidia configuration to associate a high-performance graphics software with the Nvidia card. This may be a reason.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 22, 2018, 04:29:49 AM
All right, I made a simple Direct2D application and now it will work for everybody with Windows 10 and Windows 8.1 (I tested in a virtual machine). It will not render in Windows 7 because Windows 7 does not have the Segoe UI Emoji font by default, I don't know if installing  (https://support.microsoft.com/en-us/help/2729094/an-update-for-the-segoe-ui-symbol-font-in-windows-7-and-in-windows-ser) it will solve. I am curious to see but I am lazy to try.

Windows 10:
(https://www.dropbox.com/s/kqqsa9vygicuac4/colorfontwin10.jpg?dl=1)

Windows 8.1 (lots of characters missing  :():
(https://www.dropbox.com/s/q52r6osm7zxkpuj/colorfontwin81.jpg?dl=1)

Well, I have done it C. I will post the source code when I convert to ASM. It is small and easy to convert but I can't tell when I will do it.
So, for now I only leave the .exe.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 22, 2018, 05:16:07 AM
Windows 8.1 don't render svg.
Window 7 don't render Color fonts, so blank window.

That link was from year 2012 and last update for segoeui is 2018-05-11 in my Windows 7 PC.

EDIT: seguiemj.ttf for M$ Office 2013 and be creative and use 7Zip to unpack it.
         updated Segoe UI emoji font (https://support.microsoft.com/en-gb/help/4011155/august-7-2018-update-for-office-2013-kb4011155)
Quote
File identifier    File name    File version    File size    Date    Time
Seguiemj.ttf    Seguiemj.ttf    Not applicable    1,788,856    18-Jul-2018    14:11
EDIT: for Office 2016 (https://support.microsoft.com/en-us/help/3203471/july-5-2017-update-for-office-2016-kb3203471)
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: mabdelouahab on October 22, 2018, 05:35:11 AM
windows 8.1 x64
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 22, 2018, 05:45:15 PM
Right, no color fun in Windows 7

(https://www.dropbox.com/s/z4yj7e6h7rwuzu2/colorfontWin7.jpg?dl=1)

This is a link to download the Segoe UI Emoji font (https://www.wfonts.com/font/segoe-ui-emoji), the last I posted was for Segoe UI Symbol. However the code I left here yesterday will not render it in Windows 7 because is using the flag D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 23, 2018, 05:16:34 AM
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).





Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 23, 2018, 08:04:18 PM
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.  :(

(https://www.dropbox.com/s/nn1cypbxbmju913/colorfontwin81_2.jpg?dl=1)
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 23, 2018, 09:13:17 PM
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) (https://docs.microsoft.com/en-us/windows/desktop/DirectWrite/custom-font-collections)
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: felipe on October 23, 2018, 11:28:34 PM
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:
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 24, 2018, 01:37:02 AM
@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:
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: 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;)
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 (https://support.microsoft.com/en-gb/help/4011155/august-7-2018-update-for-office-2013-kb4011155)
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: jj2007 on October 26, 2018, 05:39:04 PM
 :t on Win7-64
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 26, 2018, 06:24:37 PM
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

(https://www.dropbox.com/s/8bwsc9gwkwry2cj/subclassed1.jpg?dl=1)

And also in Windows 7 after giving it some color (in Windows 7 the RichEdit version for msftedit.dll is 4.1).
(https://www.dropbox.com/s/hfbuxhgm7xbv7gk/subclassed2.jpg?dl=1)

It is about time Microsoft makes some really innovative work on RichEdit.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: jj2007 on October 27, 2018, 04:00:12 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
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 27, 2018, 05:37:22 PM
@jj2007
With AddFontResource[Ex] and RemoveFontResource[Ex] you can use font without installing font.

The example was for using font without installing it.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: jj2007 on October 27, 2018, 07:21:57 PM
With AddFontResource[Ex] and RemoveFontResource[Ex] you can use font without installing font.
Good to know, thanks. AddFontMemResourceEx (https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-addfontmemresourceex) would be even more interesting then, but of course, it implies that you ship a very bloated exe, about 1MB.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 27, 2018, 07:54:21 PM
A puzzle, what are those IIDs:
Code: [Select]
[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.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 28, 2018, 09:40:10 PM
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  (http://www.codeguru.com/code/legacy/richedit/RTFDraw_src.zip)).
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:

 
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TimoVJL on October 28, 2018, 10:54:48 PM
ITextHost Class (https://docs.microsoft.com/en-us/windows/desktop/api/textserv/nl-textserv-itexthost)
Quote
You must implement the ITextHost interface before you call the CreateTextServices function.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 28, 2018, 11:07:18 PM
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;
}
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on October 29, 2018, 12:10:49 AM
Here is the Yves Maurer full article, I thought I had lost it.
https://www.codeguru.com/cpp/controls/richedit/windowless/article.php/c5367/ITextSevices--Using-the-Windowless-RichEdit-for-Drawing-RTF.htm
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TBRANSO1 on January 20, 2019, 04:48:13 AM
Nice work guys!

But why on earth are you guys still playing with ancient OS's in 2018?  Christeee, throw those in the heap of computing history.  MS abandoned that form of OS kernel technique from that era and have gone to a hybrid linux/pre CE Millenium model.  The Linux subsystem works pretty well and has 95% of the capabilities of running a full linux system via a VM, and the HyperV VM is great!

I think that more than half of the world either has some handheld device with a different OS like mac, android, linux, or haiwei, or uwp, and the rest that have a computer, most likely are using something purchased with the new apple OS or a windows OS 10 by now.

Anyways, nice job, beautiful.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on January 20, 2019, 07:29:01 AM
 :biggrin:
There is not really a huge difference between Windows NT and Windows 10 from a low level point of view.
And we don't reaaly waste much time with Apple although UASM supports it and I have exprimented and posted in the UASM forum.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: TBRANSO1 on January 20, 2019, 08:30:31 AM
:biggrin:
There is not really a huge difference between Windows NT and Windows 10 from a low level point of view.
And we don't reaaly waste much time with Apple although UASM supports it and I have exprimented and posted in the UASM forum.

Yeah, I get it the CPU only sees registers, and binary.

However, I think that the Win CE/7/8 stuff was an attempt to make the OS more micro-kernel (aka minix like) in order to what was thought more responsive and less prone to problems, but that bit them in the arse, and went back to a reworked NT framework and making it more monolithic like Linux, is the way that I understand it from my graduate studies.  So, Win 7/8 are really outlier, obsolete frameworks and a joke and failure in OS design.  So, I think the architectural implementation is completely different, completely transparent to the end user of course.

BTW, do you have the source code?  I downloaded the zip file, but it only has the executable... I'd really like to see how to use the Unicode and DirectX in the assembly. I'd like to see how to add emojis to any code in the future.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: AW on January 20, 2019, 09:31:42 AM
Architecture changes are strongly promoted by Microsoft in the same way that car makers promote the last features for the new car models. Low level software developers will handle Windows architecture changes in the same way people with driving licenses handle different types of vehicles and new features on a particular type of vehicle - not much new to learn.   :biggrin:

I provided the source code for the initial post. Probably I did not provide for the others because were derivatives. Anyway, the examples are basic and you will learn better from the Windows SDK D2D/DirectWrite samples.
Title: Re: 64-bit DirectX 11 - Part 4 - Color Fonts
Post by: K_F on February 09, 2019, 10:25:42 AM
Busy looking at Nvidia's PTX and it's GPU versions.
I'll write a summary doc on this as from what I can see they've gone over the top wrt high level, resulting in a complicated mess.
From there I'll compare AMD GPUs... blah blah blah.

I'm looking at ways to accelerate number crunching via GPU or FPGA SOC, but GPU looks to have more bang for buck at the moment.
So that's the current route.