Skip to content

Commit 7520232

Browse files
author
git
committed
Hmm, I'd like to keep the commit content secret.
This commit makes mactype uncompilable with standard FreeType.
1 parent 10d741e commit 7520232

File tree

5 files changed

+169
-13
lines changed

5 files changed

+169
-13
lines changed

colorinvert.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
unsigned char InvertRed[256] = { 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8 };
4+
unsigned char InvertGreen[256] = { 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,253,252,251,250,249,247,246,245,244,243,242,241,240,239,237,236,235,234,233,232,231,230,228,227,226,225,224,223,222,221,220,218,217,216,215,214,213,212,211,209,208,207,206,205,204,203,202,201,199,198,197,196,195,194,193,192,190,189,188,187,186,185,184,183,181,180,179,178,177,176,175,174,173,171,170,169,168,167,166,165,164,162,161,160,159,158,157,156,155,154,152,151,150,149,148,147,146,145,143,142,141,140,139,138,137,136,134,133,132,131,130,129,128,127,126,124,123,122,121,120,119,118,117,115,114,113,112,111,110,109,108,107,105,104,103,102,101,100,99,98,96,95,94,93,92,91,90,89,88,86,85,84,83,82,81,80,79,77,76,75,74,73,72,71,70,68,67,66,65,64,63,62,61,60,58,57,56,55,54,53,52,51,49,48,47,46,45,44,43,42,41,39,38,37,36,35,34,33,32,30,29,28,27,26,25,24,23,22,20,19,18,17,16,15,14,13,11,10,9,8,7,6,5,4,2,1,0,0,0,0,0,0};
5+
unsigned char InvertBlue[256] = { 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,252,251,250,249,248,247,246,245,244,243,242,240,239,238,237,236,235,234,233,232,231,230,228,227,226,225,224,223,222,221,220,219,218,216,215,214,213,212,211,210,209,208,207,206,204,203,202,201,200,199,198,197,196,195,194,192,191,190,189,188,187,186,185,184,183,182,180,179,178,177,176,175,174,173,172,171,170,168,167,166,165,164,163,162,161,160,159,157,156,155,154,153,152,151,150,149,148,147,145,144,143,142,141,140,139,138,137,136,135,133,132,131,130,129,128,127,126,125,124,123,121,120,119,118,117,116,115,114,113,112,111,109,108,107,106,105,104,103,102,101,100,99,97,96,95,94,93,92,91,90,89,88,87,85,84,83,82,81,80,79,78,77,76,74,73,72,71,70,69,68,67,66,65,64,62,61,60,59,58,57,56,55,54,53,52,50,49,48,47,46,45,44,43,42,41,40,38,37,36,35,34,33,32,31,30,29,28,26,25,24,23,22,21,20,19,18,17,16,14,13,12,11,10,9,8,7,6,5,4,2,1,0,0,0,0,0,0 };

ft.cpp

Lines changed: 152 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include "ft2vert.h"
4646

47+
#include "colorinvert.h"
48+
4749
FT_BitmapGlyphRec empty_glyph = {};//モナサッソリヨニラヨ
4850

4951
#define FT_BOLD_LOW 15
@@ -445,6 +447,7 @@ typedef struct
445447
int AAMode; //antialiased mode for every char
446448
CAlphaBlendColor* solid;
447449
CAlphaBlendColor* shadow; //alpha blender
450+
bool bInvertColor; // invert color for chrome/skia
448451
} FreeTypeGlyphInfo, *PFreeTypeGlyphInfo;
449452

450453

@@ -612,6 +615,122 @@ static void FreeTypeDrawBitmapPixelModeLCD(FreeTypeGlyphInfo& FTGInfo,
612615
}
613616
}
614617

618+
COLORREF _rgbamixer(COLORREF bkColor, int b, int g, int r, int a) {
619+
int bkr = GetRValue(bkColor), bkg = GetGValue(bkColor), bkb = GetBValue(bkColor);
620+
return a << 24 | (bkb - a*bkb / 255 + b) << 16 | (bkg - a*bkg / 255 + g) << 8 | (bkr - a*bkr / 255 + r);
621+
}
622+
623+
// color blender for color font
624+
COLORREF _invert_rgbamixer(COLORREF bkColor, int b, int g, int r, int a) {
625+
if (!a)
626+
return bkColor;
627+
int invertr = InvertRed[Min(r * 255 / a, 255)] * a / 255;
628+
int invertg = InvertGreen[Min(g * 255 / a, 255)] * a / 255;
629+
int invertb = InvertBlue[Min(b * 255 / a, 255)] * a / 255;
630+
return _rgbamixer(bkColor, invertb, invertg, invertr, a);
631+
}
632+
633+
// draw color emoji
634+
static void FreeTypeDrawBitmapPixelModeBGRA(FreeTypeGlyphInfo& FTGInfo, int x, int y)
635+
{
636+
CBitmapCache& cache = *FTGInfo.FTInfo->pCache;
637+
const FT_Bitmap *bitmap = &FTGInfo.FTGlyph->bitmap;
638+
BYTE alphatuner = FTGInfo.FTInfo->params->alphatuner;
639+
int AAMode = FTGInfo.AAMode;
640+
int i, j;
641+
int dx, dy; // display
642+
FT_Bytes p;
643+
644+
if (bitmap->pixel_mode != FT_PIXEL_MODE_BGRA) {
645+
return;
646+
}
647+
648+
const COLORREF color = FTGInfo.FTInfo->Color();
649+
650+
const SIZE cachebufsize = cache.Size();
651+
DWORD * const cachebufp = (DWORD *)cache.GetPixels();
652+
DWORD * cachebufrowp;
653+
typedef COLORREF (*pfnmixer) (COLORREF bkColor, int b, int g, int r, int a);
654+
655+
pfnmixer mixer = FTGInfo.bInvertColor? _invert_rgbamixer:_rgbamixer;
656+
657+
int left, top, width, height;
658+
if (x < 0) {
659+
left = -x * 4;
660+
x = 0;
661+
}
662+
else {
663+
left = 0;
664+
}
665+
width = Min((int)bitmap->width*4, (int)(cachebufsize.cx - x) * 4);
666+
top = 0;
667+
height = bitmap->rows;
668+
669+
COLORREF backColor, newColor;
670+
unsigned int alphaR, alphaG, alphaB, alpha;
671+
BOOL bAlphaDraw = FTGInfo.FTInfo->params->alpha != 1;
672+
673+
if (bAlphaDraw)
674+
for (j = 0, dy = y; j < height; ++j, ++dy) {
675+
if ((unsigned int)dy >= (unsigned int)cachebufsize.cy) continue;
676+
677+
p = bitmap->pitch < 0 ?
678+
&bitmap->buffer[(-bitmap->pitch * bitmap->rows) - bitmap->pitch * j] : // up-flow
679+
&bitmap->buffer[bitmap->pitch * j]; // down-flow
680+
681+
cachebufrowp = &cachebufp[dy * cachebufsize.cx];
682+
for (i = left, dx = x; i < width; i += 4, ++dx) {
683+
backColor = cachebufrowp[dx];
684+
COLORREF last = 0xFFFFFFFF;
685+
if (AAMode == 2 || AAMode == 4) {
686+
alphaR = p[i + 0] / alphatuner;
687+
alphaG = p[i + 1] / alphatuner;
688+
alphaB = p[i + 2] / alphatuner;
689+
alpha = p[i + 3] / alphatuner;
690+
}
691+
else {
692+
// BGR
693+
alphaR = p[i + 2] / alphatuner;
694+
alphaG = p[i + 1] / alphatuner;
695+
alphaB = p[i + 0] / alphatuner;
696+
alpha = p[i + 3] / alphatuner;
697+
}
698+
699+
newColor = mixer(backColor, alphaB, alphaG, alphaR, alpha);
700+
cachebufrowp[dx] = newColor;
701+
}
702+
}
703+
else
704+
for (j = 0, dy = y; j < height; ++j, ++dy) {
705+
if ((unsigned int)dy >= (unsigned int)cachebufsize.cy) continue;
706+
707+
p = bitmap->pitch < 0 ?
708+
&bitmap->buffer[(-bitmap->pitch * bitmap->rows) - bitmap->pitch * j] : // up-flow
709+
&bitmap->buffer[bitmap->pitch * j]; // down-flow
710+
711+
cachebufrowp = &cachebufp[dy * cachebufsize.cx];
712+
for (i = left, dx = x; i < width; i += 4, ++dx) {
713+
backColor = cachebufrowp[dx];
714+
COLORREF last = 0xFFFFFFFF;
715+
if (AAMode == 2 || AAMode == 4) {
716+
alphaR = p[i + 0];
717+
alphaG = p[i + 1];
718+
alphaB = p[i + 2];
719+
alpha = p[i + 3];
720+
}
721+
else {
722+
// BGR
723+
alphaR = p[i + 2];
724+
alphaG = p[i + 1];
725+
alphaB = p[i + 0];
726+
alpha = p[i + 3];
727+
}
728+
newColor = mixer(backColor, alphaB, alphaG, alphaR, alpha);
729+
cachebufrowp[dx] = newColor;
730+
}
731+
}
732+
}
733+
615734
static void FreeTypeDrawBitmapGray(FreeTypeGlyphInfo& FTGInfo, CAlphaBlendColor& ab, int x, int y)
616735
{
617736
int i, j;
@@ -675,6 +794,9 @@ static void FreeTypeDrawBitmap(
675794
case FT_PIXEL_MODE_LCD:
676795
FreeTypeDrawBitmapPixelModeLCD(FTGInfo, ab, x, y);
677796
break;
797+
case FT_PIXEL_MODE_BGRA:
798+
FreeTypeDrawBitmapPixelModeBGRA(FTGInfo, x, y);
799+
break;
678800
default:
679801
return; // 未対応
680802
}
@@ -851,6 +973,9 @@ static void FreeTypeDrawBitmapV(FreeTypeGlyphInfo& FTGInfo, CAlphaBlendColor& ab
851973
case FT_PIXEL_MODE_LCD_V:
852974
FreeTypeDrawBitmapPixelModeLCDV(FTGInfo, ab, x, y);
853975
break;
976+
case FT_PIXEL_MODE_BGRA:
977+
FreeTypeDrawBitmapPixelModeBGRA(FTGInfo, x, y);
978+
break;
854979
default:
855980
return; // 未対応
856981
}
@@ -1497,6 +1622,7 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
14971622
FreeTypeFontCache* pftCache = FTInfo.pftCache;
14981623
const CFontSettings*& pfs = FTInfo.pfs;
14991624
FreeTypeFontInfo*& pfi = FTInfo.pfi;
1625+
const bool bLoadColor = pSettings->LoadColorFont();
15001626
const bool bGlyphIndex = FTInfo.IsGlyphIndex();
15011627
//const bool bSizeOnly = FTInfo.IsSizeOnly();
15021628
//const bool bOwnCache = !(FTInfo.font_type.flags & FT_LOAD_RENDER);
@@ -1626,6 +1752,8 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
16261752
freetype_face = FTInfo.GetFace(j); //ヘャハアク�ツカヤモヲfaceidオトハオシハface
16271753
//スモマツタエク�ツカヤモヲオトfontsetting
16281754
FTInfo.font_type.flags = FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
1755+
if (bLoadColor && FT_HAS_COLOR(freetype_face))
1756+
FTInfo.font_type.flags |= FT_LOAD_COLOR; // load color font if requested and font supports it
16291757
// ヒンティング
16301758
//extern CFontSetCache g_fsetcache;
16311759
//pfs = g_fsetcache.Get(FTInfo.font_type.face_id);
@@ -1890,6 +2018,14 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
18902018
}
18912019
{
18922020
CCriticalSectionLock __lock(CCriticalSectionLock::CS_LIBRARY);
2021+
if (bLoadColor) {
2022+
// use custom API to get color bitmap
2023+
if (FT_Glyph_To_BitmapEx(&((*glyph_bitmap)->ft_glyph), render_mode, 0, 1, 1, glyph_index, freetype_face)) {
2024+
FT_Done_Ref_Glyph(glyph_bitmap);
2025+
nRet = false;
2026+
goto gdiexit;
2027+
}
2028+
} else
18932029
if(FT_Glyph_To_Bitmap(&((*glyph_bitmap)->ft_glyph), render_mode, 0, 1)){
18942030
FT_Done_Ref_Glyph(glyph_bitmap);
18952031
nRet= false;
@@ -1907,8 +2043,19 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
19072043
int dy = clpdx.gety(0); //サテク゚カネ
19082044
int dx = clpdx.get(bWidthGDI32 ? gdi32x : cx); //サテソ昮ネ
19092045
int left = FT_BitmapGlyph((*glyph_bitmap)->ft_glyph)->left;
1910-
if (FTInfo.x + left< FTInfo.xBase)
1911-
FTInfo.xBase = FTInfo.x + left; //ネ郢﨧ミラヨキ鈹ヌクコハニシホサヨテオト」ィコマウノキ釚ナ」ゥ」ャ オ鉸トラヨオトニシホサヨテ
2046+
if (gdi32x == 0) { // zero width text (most likely a diacritic)
2047+
if (FTInfo.x + dx + left < FTInfo.xBase)
2048+
FTInfo.xBase = FTInfo.x + dx + left;
2049+
//it needs to be drawn at the end of the offset (Windows specific, Windows will "share" half of letter's width to the diacritic)
2050+
if (i > 0) {
2051+
// we need to update the logical start position of the previous letter to compensate the strange behavior.
2052+
*(Dx - 1) = FTInfo.x + dx;
2053+
}
2054+
}
2055+
else {
2056+
if (FTInfo.x + left < FTInfo.xBase)
2057+
FTInfo.xBase = FTInfo.x + left; //ネ郢﨧ミラヨキ鈹ヌクコハニシホサヨテオト」ィコマウノキ釚ナ」ゥ」ャ オ鉸トラヨオトニシホサヨテ
2058+
}
19122059

19132060
if (lpString < lpEnd - 1) {
19142061
FTInfo.x += dx;
@@ -2602,18 +2749,18 @@ BOOL FreeTypeTextOut(
26022749

26032750
//===============シニヒ耋�ノ==========================
26042751

2605-
FreeTypeGlyphInfo FTGInfo = {&FTInfo, 0, 0, 0, solid, shadow};
2752+
FreeTypeGlyphInfo FTGInfo = {&FTInfo, 0, 0, 0, solid, shadow, pSettings->InvertColor()};
26062753
for (int i=0; i<cbString; ++i, ++lpString)
26072754
{
26082755
WCHAR wch = *lpString;
2609-
if (Glyphs[i])
2756+
if (Glyphs[i]) // paint text with FreeType
26102757
{
26112758
FTGInfo.wch = wch;
26122759
FTGInfo.FTGlyph = (FT_BitmapGlyph)(Glyphs[i]->ft_glyph);
26132760
FTGInfo.AAMode = FTInfo.AAModes[i];
26142761
TextOutCallback(FTGInfo);
26152762
}
2616-
else
2763+
else // paint text(bitmap) with gdi
26172764
{
26182765
int j = i;
26192766
FT_DRAW_STATE st= drState[i];

hook.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
473473

474474
//4
475475
{
476-
#ifdef INFINALITY
477-
// enable infinality exclusive features
478-
FT_initEnv();
476+
#ifdef INFINALITY
477+
// enable infinality exclusive features
478+
FT_initEnv();
479479
#endif
480480
CGdippSettings* pSettings = CGdippSettings::CreateInstance();
481481
if (!pSettings || !pSettings->LoadSettings(instance)) {
@@ -486,7 +486,6 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
486486
bEnableDW = pSettings->DirectWrite();
487487
}
488488
if (!IsUnload) hook_initinternal(); //イサシモヤリオトト」ソ鮴ヘイサラホコホハツヌ
489-
490489
//5
491490
if (!IsProcessExcluded() && !IsUnload) {
492491
#ifndef _WIN64
@@ -571,9 +570,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
571570
delete g_pFTEngine;
572571
}
573572

574-
#ifdef INFINALITY
575-
// enable infinality exclusive features
576-
FT_freeEnv();
573+
#ifdef INFINALITY
574+
// enable infinality exclusive features
575+
FT_freeEnv();
577576
#endif
578577
//if (g_alterGUIFont)
579578
// DeleteObject(g_alterGUIFont);

settings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ bool CGdippSettings::LoadAppSettings(LPCTSTR lpszFile)
496496

497497
//experimental settings:
498498
m_bEnableClipBoxFix = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ClipBoxFix"), 1, lpszFile);
499-
499+
m_bColorFont = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ColorFont"), 0, lpszFile);
500+
m_bInvertColor = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("InvertColor"), 0, lpszFile);
500501
#ifdef INFINALITY
501502
// define some macros
502503
#define INF_INT_ENV(y, def) \

settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class CGdippSettings
288288

289289
//settings for experimental
290290
bool m_bEnableClipBoxFix;
291+
bool m_bColorFont;
292+
bool m_bInvertColor;
291293

292294

293295
//settings for directwrite
@@ -445,6 +447,8 @@ class CGdippSettings
445447
int WidthMode() const { return m_nWidthMode; }
446448
int FontLoader() const { return m_nFontLoader; }
447449
bool EnableClipBoxFix() const { return m_bEnableClipBoxFix; }
450+
bool LoadColorFont() const { return m_bColorFont; }
451+
bool InvertColor() const { return m_bInvertColor; }
448452
DWORD ShadowLightColor() const { return m_nShadowLightColor; }
449453
DWORD ShadowDarkColor() const { return m_nShadowDarkColor; }
450454
int FontSubstitutes() const { return m_nFontSubstitutes; } //ナミカマフ貊サト」ハス

0 commit comments

Comments
 (0)