Page 1 of 1

How to display emojis original colors?

Posted: 18 May 2021, 11:43
by kauan014

Code: Select all

gui,add,text,x0 y0,✔❤😁😁😁😂🤣😎🎉
gui,add,text,x0 y+10 cred,✔❤😁😁😁😂🤣😎🎉
gui,show,h150,
They are shown without color.
I can change the color using ccolor but i would like to show their original color, as it show here on the forum ^

image.png
image.png (12.32 KiB) Viewed 1200 times

Re: How to display emojis original colors?

Posted: 26 May 2021, 08:10
by SirSocks
I second this post *Bump*

I attempted to use ActiveX to display the emojis, which doesn't work. 😣

Code: Select all

html_text = <html><a>Here are some emojis. 😃 👍</a></html>
gui,add,ActiveX,w200 h100 vWB, shell explorer
wb.Navigate("about:blank")
wb.document.write(html_text)
gui,show,
return

GuiClose:
ExitApp
Image

Re: How to display emojis original colors?

Posted: 11 Sep 2021, 19:58
by AHKStudent
I third this post bump

If anyone found a solution please post

Re: How to display emojis original colors?

Posted: 12 Sep 2021, 00:56
by safetycar
Related to this I found the other day an example inside a different type of project, GridGUI by @Capn Odin, an example (Example Unicode.ahk) that used emojis.

The relevant line could be summarized to this:

Code: Select all

Gui, Add, ActiveX, w800 h100, % "about:<!DOCTYPE HTML><head><meta charset=""UTF-8""></head><html><body style=""{margin:0;background-color:#F0F0F0;}""><p style=""font-size:50px;font-family:segoe ui emoji;"">" "🦧🐶🐕🦮🐕‍🦺🐩🐺🦊🦝🐱🐈🐈‍⬛🦁🐯🐅🐆🐴🐎🦄" "</p></body></html>"
Gui, Show

Re: How to display emojis original colors?

Posted: 12 Sep 2021, 02:31
by AHKStudent
safetycar wrote:
12 Sep 2021, 00:56
Related to this I found the other day an example inside a different type of project, GridGUI by @Capn Odin, an example (Example Unicode.ahk) that used emojis.

The relevant line could be summarized to this:

Code: Select all

Gui, Add, ActiveX, w800 h100, % "about:<!DOCTYPE HTML><head><meta charset=""UTF-8""></head><html><body style=""{margin:0;background-color:#F0F0F0;}""><p style=""font-size:50px;font-family:segoe ui emoji;"">" "🦧🐶🐕🦮🐕‍🦺🐩🐺🦊🦝🐱🐈🐈‍⬛🦁🐯🐅🐆🐴🐎🦄" "</p></body></html>"
Gui, Show
thank you, that is very helpful. I wonder if someone has code to use emojis in text controls so then you could easily update them with GuiControl

Re: How to display emojis original colors?

Posted: 12 Sep 2021, 06:59
by Hellbent
AHKStudent wrote:
12 Sep 2021, 02:31
I wonder if someone has code to use emojis in text controls so then you could easily update them with GuiControl
You could just use a png set of them.
Combine them in a strip, save the strip in B64 and include a function in your script to separate the strip into its parts for easy display.

Re: How to display emojis original colors?

Posted: 12 Sep 2021, 22:59
by AHKStudent
Hellbent wrote:
12 Sep 2021, 06:59
AHKStudent wrote:
12 Sep 2021, 02:31
I wonder if someone has code to use emojis in text controls so then you could easily update them with GuiControl
You could just use a png set of them.
Combine them in a strip, save the strip in B64 and include a function in your script to separate the strip into its parts for easy display.
very helpful tip, thanks

Re: How to display emojis original colors?

Posted: 13 Sep 2021, 04:22
by swagfag
best start learning DirectWrite
image.png
image.png (210 KiB) Viewed 958 times

Code: Select all

#Requires AutoHotkey v1.1.33+
#NoEnv
#SingleInstance Force
#Warn All
SetBatchLines -1

w := h := 450
Gui New, +AlwaysOnTop +HwndhwndGui
Gui Show, w%w% h%h% NoActivate, % A_AhkVersion ": get some emoji going"

GuiClose() {
	ExitApp
}

d2d1 := DllCall("LoadLibrary", "Str", "d2d1.dll", "Ptr")
dwrite := DllCall("LoadLibrary", "Str", "dwrite.dll", "Ptr")
ole32 := DllCall("LoadLibrary", "Str", "ole32.dll", "Ptr")

VarSetCapacity(IID_ID2D1Factory, 16)
DllCall("ole32\CLSIDFromString", "Str", "{06152247-6f50-465a-9245-118bfd3b6007}", "Ptr", &IID_ID2D1Factory)

; HRESULT D2D1CreateFactory(
;   D2D1_FACTORY_TYPE          factoryType,
;   REFIID                     riid,
;   const D2D1_FACTORY_OPTIONS *pFactoryOptions,
;   void                       **ppIFactory
; );
DllCall("d2d1\D2D1CreateFactory"
	, "Int", 0 ; D2D1_FACTORY_TYPE_SINGLE_THREADED
	, "Ptr", &IID_ID2D1Factory
	, "Ptr", 0 ; D2D1_FACTORY_OPTIONS
	, "Ptr*", pID2D1Factory := 0)

; ID2D1Factory : public IUnknown
;  0: QueryInterface
;  1: AddRef
;  2: Release
;  3: ReloadSystemMetrics
;  4: GetDesktopDpi
;  5: CreateRectangleGeometry
;  6: CreateRoundedRectangleGeometry
;  7: CreateEllipseGeometry
;  8: CreateGeometryGroup
;  9: CreateTransformedGeometry
; 10: CreatePathGeometry
; 11: CreateStrokeStyle
; 12: CreateDrawingStateBlock
; 13: CreateWicBitmapRenderTarget
; 14: CreateHwndRenderTarget
; 15: CreateDxgiSurfaceRenderTarget
; 16: CreateDCRenderTarget

; typedef struct D2D1_RENDER_TARGET_PROPERTIES {
;   D2D1_RENDER_TARGET_TYPE  type;
;   D2D1_PIXEL_FORMAT        pixelFormat;
;   FLOAT                    dpiX;
;   FLOAT                    dpiY;
;   D2D1_RENDER_TARGET_USAGE usage;
;   D2D1_FEATURE_LEVEL       minLevel;
; } D2D1_RENDER_TARGET_PROPERTIES;
VarSetCapacity(renderTargetProperties, 28, 0) ; zero initialize -> all defaults

; typedef struct D2D1_HWND_RENDER_TARGET_PROPERTIES {
;   HWND                 hwnd;
;   D2D1_SIZE_U          pixelSize;
;   D2D1_PRESENT_OPTIONS presentOptions;
; } D2D1_HWND_RENDER_TARGET_PROPERTIES;
VarSetCapacity(hwndRenderTargetProperties, (A_PtrSize = 4) ? 16 : 24)
NumPut(hwndGui, hwndRenderTargetProperties, 0, "Ptr")
NumPut(w, hwndRenderTargetProperties, A_PtrSize, "UInt")
NumPut(h, hwndRenderTargetProperties, A_PtrSize + 4, "UInt")
NumPut(0, hwndRenderTargetProperties, A_PtrSize + 8, "UInt") ; D2D1_PRESENT_OPTIONS_NONE

; HRESULT CreateHwndRenderTarget(
;   const D2D1_RENDER_TARGET_PROPERTIES &      renderTargetProperties,
;   const D2D1_HWND_RENDER_TARGET_PROPERTIES & hwndRenderTargetProperties,
;   ID2D1HwndRenderTarget                      **hwndRenderTarget
; );
; 14: CreateHwndRenderTarget
DllCall(vtbl(14, pID2D1Factory), "Ptr", pID2D1Factory
	, "Ptr", &renderTargetProperties
	, "Ptr", &hwndRenderTargetProperties
	, "Ptr*", pHwndRenderTarget := 0)

vtbl(methodIndex, rawComPtr) {
	return NumGet(NumGet(rawComPtr+0, "Ptr") + A_PtrSize * methodIndex, "Ptr")
}

; ID2D1RenderTarget : public ID2D1Resource : public IUnknown
;  0: QueryInterface
;  1: AddRef
;  2: Release
;  3: GetFactory
;  4: CreateBitmap
;  5: CreateBitmapFromWicBitmap
;  6: CreateSharedBitmap
;  7: CreateBitmapBrush
;  8: CreateSolidColorBrush
;  9: CreateGradientStopCollection
; 10: CreateLinearGradientBrush
; 11: CreateRadialGradientBrush
; 12: CreateCompatibleRenderTarget
; 13: CreateLayer
; 14: CreateMesh
; 15: DrawLine
; 16: DrawRectangle
; 17: FillRectangle
; 18: DrawRoundedRectangle
; 19: FillRoundedRectangle
; 20: DrawEllipse
; 21: FillEllipse
; 22: DrawGeometry
; 23: FillGeometry
; 24: FillMesh
; 25: FillOpacityMask
; 26: DrawBitmap
; 27: DrawText
; 28: DrawTextLayout
; 29: DrawGlyphRun
; 30: SetTransform
; 31: GetTransform
; 32: SetAntialiasMode
; 33: GetAntialiasMode
; 34: SetTextAntialiasMode
; 35: GetTextAntialiasMode
; 36: SetTextRenderingParams
; 37: GetTextRenderingParams
; 38: SetTags
; 39: GetTags
; 40: PushLayer
; 41: PopLayer
; 42: Flush
; 43: SaveDrawingState
; 44: RestoreDrawingState
; 45: PushAxisAlignedClip
; 46: PopAxisAlignedClip
; 47: Clear
; 48: BeginDraw
; 49: EndDraw
; 50: GetPixelFormat
; 51: SetDpi
; 52: GetDpi
; 53: GetSize
; 54: GetPixelSize
; 55: GetMaximumBitmapSize
; 56: IsSupported

; struct D3DCOLORVALUE {
;   FLOAT r;
;   FLOAT g;
;   FLOAT b;
;   FLOAT a;
; };
VarSetCapacity(fontBrushColor, 16) ; black
NumPut(0, fontBrushColor, 0, "Float")
NumPut(0, fontBrushColor, 4, "Float")
NumPut(0, fontBrushColor, 8, "Float")
NumPut(1, fontBrushColor, 12, "Float")

; HRESULT CreateSolidColorBrush(
;   const D2D1_COLOR_F &          color,
;   const D2D1_BRUSH_PROPERTIES & brushProperties,
;   ID2D1SolidColorBrush          **solidColorBrush
; );
; 8: CreateSolidColorBrush
DllCall(vtbl(8, pHwndRenderTarget), "Ptr", pHwndRenderTarget
	, "Ptr", &fontBrushColor
	, "Ptr", 0 ; default brush properties
	, "Ptr*", pBrush := 0)

VarSetCapacity(IID_IDWriteFactory, 16)
DllCall("ole32\CLSIDFromString", "Str", "{b859ee5a-d838-4b5b-a2e8-1adc7d93db48}", "Ptr", &IID_IDWriteFactory)

; HRESULT DWriteCreateFactory(
;   DWRITE_FACTORY_TYPE factoryType,
;   REFIID              iid,
;   IUnknown            **factory
; );
DllCall("dwrite\DWriteCreateFactory"
	, "Int", 0 ; DWRITE_FACTORY_TYPE_SHARED
	, "Ptr", &IID_IDWriteFactory
	, "Ptr*", pIDWriteFactory := 0)

; IDWriteFactory : public IUnknown
;  3: GetSystemFontCollection
;  4: CreateCustomFontCollection
;  5: RegisterFontCollectionLoader
;  6: UnregisterFontCollectionLoader
;  7: CreateFontFileReference
;  8: CreateCustomFontFileReference
;  9: CreateFontFace
; 10: CreateRenderingParams
; 11: CreateMonitorRenderingParams
; 12: CreateCustomRenderingParams
; 13: RegisterFontFileLoader
; 14: UnregisterFontFileLoader
; 15: CreateTextFormat
; 16: CreateTypography
; 17: GetGdiInterop
; 18: CreateTextLayout
; 19: CreateGdiCompatibleTextLayout
; 20: CreateEllipsisTrimmingSign
; 21: CreateTextAnalyzer
; 22: CreateNumberSubstitution
; 23: CreateGlyphRunAnalysis

; HRESULT CreateTextFormat(
;   WCHAR const           *fontFamilyName,
;   IDWriteFontCollection *fontCollection,
;   DWRITE_FONT_WEIGHT    fontWeight,
;   DWRITE_FONT_STYLE     fontStyle,
;   DWRITE_FONT_STRETCH   fontStretch,
;   FLOAT                 fontSize,
;   WCHAR const           *localeName,
;   IDWriteTextFormat     **textFormat
; );
; 15: CreateTextFormat
DllCall(vtbl(15, pIDWriteFactory), "Ptr", pIDWriteFactory
	, "WStr", "Segoe UI Emoji"
	, "Ptr", 0 ; fontCollection
	, "Int", 400 ; DWRITE_FONT_WEIGHT_NORMAL
	, "Int", 0 ; DWRITE_FONT_STYLE_NORMAL
	, "Int", 5 ; DWRITE_FONT_STRETCH_NORMAL
	, "Float", 18 ; fontSize
	, "WStr", "" ; localeName
	, "Ptr*", pTextFormat := 0)

; void BeginDraw();
; 48: BeginDraw
DllCall(vtbl(48, pHwndRenderTarget), "Ptr", pHwndRenderTarget)

; struct D3DCOLORVALUE {
;   FLOAT r;
;   FLOAT g;
;   FLOAT b;
;   FLOAT a;
; };
VarSetCapacity(backgroundColor, 16) ; grey
NumPut(0.9, backgroundColor, 0, "Float")
NumPut(0.9, backgroundColor, 4, "Float")
NumPut(0.9, backgroundColor, 8, "Float")
NumPut(1.0, backgroundColor, 12, "Float")

; void Clear(
;   const D2D1_COLOR_F *clearColor
; );
; 47: Clear
DllCall(vtbl(47, pHwndRenderTarget), "Ptr", pHwndRenderTarget, "Ptr", &backgroundColor)

text := "🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌍🌎🌏🌒🌓🌔🌕🌖🌗🌘🌝🌞🌱🌲🌳🌴🌷🌹🌻🌽🌾🍅🍆🍇🍈🍉🍌🍍🍎🍏🍐🍑🍒🍓🍔🍕🍖🍗🍘🍛🍜🍝🍟🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯🍰🍱🍲🍳🍵🍹🍺🍻🍼🎂🎃🎄🎅🎆🎇🎉🎊🎋🎌🎍🎎🎐🎑🎓🎠🎡🎢🎣🎤🎦🎨🎯🎰🎱🎳🎴🎻🎼🎾🎿🏀🏁🏂🏄🏇🏊🏡🏤🏦🏧🏩🏫🏬🐌🐓🐝🐠🐡🐢🐣🐳🐵🐶🐸🐹👆👇👈👉👊👒👔👛👝👦👧👨👩👮👯👰👱👲👳👴👵👶👷👸👹👺👼👾💂💄💅💆💇💈💉💊💋💌💐💑💒💘💝💟💨💩💱💹💺💾📈📉📊📌📍📑📓📔📛📝📟📣📵🔞🔫😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😒😓😔😖😘😚😜😝😞😠😡😢😣😤😥😨😩😪😫😭😰😱😲😳😵😶😷🙅🙆🙇🙈🙉🙊🙋🙌🙍🙎🙏🚀🚃🚄🚅🚆🚈🚉🚊🚋🚌🚍🚎🚏🚐"

; typedef struct D2D_RECT_F {
;   FLOAT left;
;   FLOAT top;
;   FLOAT right;
;   FLOAT bottom;
; } D2D_RECT_F;
VarSetCapacity(layoutRect, 16)
NumPut(0, layoutRect, 0, "Float")
NumPut(0, layoutRect, 4, "Float")
NumPut(w, layoutRect, 8, "Float")
NumPut(h, layoutRect, 12, "Float")

; void DrawText(
;   const WCHAR            *string,
;   UINT32                 stringLength,
;   IDWriteTextFormat      *textFormat,
;   const D2D1_RECT_F      *layoutRect,
;   ID2D1Brush             *defaultFillBrush,
;   D2D1_DRAW_TEXT_OPTIONS options,
;   DWRITE_MEASURING_MODE  measuringMode
; );
; 27: DrawText
DllCall(vtbl(27, pHwndRenderTarget), "Ptr", pHwndRenderTarget
	, "Str", text
	, "UInt", StrLen(text)
	, "Ptr", pTextFormat
	, "Ptr", &layoutRect
	, "Ptr", pBrush
	, "Int", 0x00000004 ; D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
	, "Int", 0) ; DWRITE_MEASURING_MODE_NATURAL

; HRESULT EndDraw(
;   D2D1_TAG *tag1,
;   D2D1_TAG *tag2
; );
; 49: EndDraw
DllCall(vtbl(49, pHwndRenderTarget), "Ptr", pHwndRenderTarget
	, "Ptr*", pTag1 := 0
	, "Ptr*", pTag2 := 0)

ObjRelease(pTextFormat)
ObjRelease(pIDWriteFactory)
ObjRelease(pBrush)
ObjRelease(pHwndRenderTarget)
ObjRelease(pID2D1Factory)