Author Topic: 64-bit DirectX 11 - Part 4 - Color Fonts  (Read 3939 times)

AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #15 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).






AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #16 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.  :(


TimoVJL

  • Member
  • ***
  • Posts: 433
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #17 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)
« Last Edit: October 26, 2018, 04:16:59 PM by TimoVJL »
May the source be with you

felipe

  • Member
  • *****
  • Posts: 1249
  • Eagles are just great!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #18 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:
Felipe.

AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #19 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:
« Last Edit: October 24, 2018, 02:51:27 AM by AW »

TimoVJL

  • Member
  • ***
  • Posts: 433
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #20 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
« Last Edit: October 27, 2018, 01:34:59 AM by TimoVJL »
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 9687
  • Assembler is fun ;-)
    • MasmBasic
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #21 on: October 26, 2018, 05:39:04 PM »
 :t on Win7-64

AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #22 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



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

  • Member
  • *****
  • Posts: 9687
  • Assembler is fun ;-)
    • MasmBasic
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #23 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

TimoVJL

  • Member
  • ***
  • Posts: 433
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #24 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.
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 9687
  • Assembler is fun ;-)
    • MasmBasic
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #25 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 would be even more interesting then, but of course, it implies that you ship a very bloated exe, about 1MB.

TimoVJL

  • Member
  • ***
  • Posts: 433
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #26 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.
« Last Edit: October 28, 2018, 12:01:09 AM by TimoVJL »
May the source be with you

AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #27 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 ).
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

  • Member
  • ***
  • Posts: 433
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #28 on: October 28, 2018, 10:54:48 PM »
ITextHost Class
Quote
You must implement the ITextHost interface before you call the CreateTextServices function.
May the source be with you

AW

  • Member
  • *****
  • Posts: 2316
  • Let's Make ASM Great Again!
Re: 64-bit DirectX 11 - Part 4 - Color Fonts
« Reply #29 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;
}