Skip to content

Commit

Permalink
Hmm, I'd like to keep the commit content secret.
Browse files Browse the repository at this point in the history
This commit makes mactype uncompilable with standard FreeType.
  • Loading branch information
git committed Nov 7, 2018
1 parent 10d741e commit 7520232
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 13 deletions.
5 changes: 5 additions & 0 deletions colorinvert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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 };
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};
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 };
157 changes: 152 additions & 5 deletions ft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

#include "ft2vert.h"

#include "colorinvert.h"

FT_BitmapGlyphRec empty_glyph = {};//モナサッソリヨニラヨ

#define FT_BOLD_LOW 15
Expand Down Expand Up @@ -445,6 +447,7 @@ typedef struct
int AAMode; //antialiased mode for every char
CAlphaBlendColor* solid;
CAlphaBlendColor* shadow; //alpha blender
bool bInvertColor; // invert color for chrome/skia
} FreeTypeGlyphInfo, *PFreeTypeGlyphInfo;


Expand Down Expand Up @@ -612,6 +615,122 @@ static void FreeTypeDrawBitmapPixelModeLCD(FreeTypeGlyphInfo& FTGInfo,
}
}

COLORREF _rgbamixer(COLORREF bkColor, int b, int g, int r, int a) {
int bkr = GetRValue(bkColor), bkg = GetGValue(bkColor), bkb = GetBValue(bkColor);
return a << 24 | (bkb - a*bkb / 255 + b) << 16 | (bkg - a*bkg / 255 + g) << 8 | (bkr - a*bkr / 255 + r);
}

// color blender for color font
COLORREF _invert_rgbamixer(COLORREF bkColor, int b, int g, int r, int a) {
if (!a)
return bkColor;
int invertr = InvertRed[Min(r * 255 / a, 255)] * a / 255;
int invertg = InvertGreen[Min(g * 255 / a, 255)] * a / 255;
int invertb = InvertBlue[Min(b * 255 / a, 255)] * a / 255;
return _rgbamixer(bkColor, invertb, invertg, invertr, a);
}

// draw color emoji
static void FreeTypeDrawBitmapPixelModeBGRA(FreeTypeGlyphInfo& FTGInfo, int x, int y)
{
CBitmapCache& cache = *FTGInfo.FTInfo->pCache;
const FT_Bitmap *bitmap = &FTGInfo.FTGlyph->bitmap;
BYTE alphatuner = FTGInfo.FTInfo->params->alphatuner;
int AAMode = FTGInfo.AAMode;
int i, j;
int dx, dy; // display
FT_Bytes p;

if (bitmap->pixel_mode != FT_PIXEL_MODE_BGRA) {
return;
}

const COLORREF color = FTGInfo.FTInfo->Color();

const SIZE cachebufsize = cache.Size();
DWORD * const cachebufp = (DWORD *)cache.GetPixels();
DWORD * cachebufrowp;
typedef COLORREF (*pfnmixer) (COLORREF bkColor, int b, int g, int r, int a);

pfnmixer mixer = FTGInfo.bInvertColor? _invert_rgbamixer:_rgbamixer;

int left, top, width, height;
if (x < 0) {
left = -x * 4;
x = 0;
}
else {
left = 0;
}
width = Min((int)bitmap->width*4, (int)(cachebufsize.cx - x) * 4);
top = 0;
height = bitmap->rows;

COLORREF backColor, newColor;
unsigned int alphaR, alphaG, alphaB, alpha;
BOOL bAlphaDraw = FTGInfo.FTInfo->params->alpha != 1;

if (bAlphaDraw)
for (j = 0, dy = y; j < height; ++j, ++dy) {
if ((unsigned int)dy >= (unsigned int)cachebufsize.cy) continue;

p = bitmap->pitch < 0 ?
&bitmap->buffer[(-bitmap->pitch * bitmap->rows) - bitmap->pitch * j] : // up-flow
&bitmap->buffer[bitmap->pitch * j]; // down-flow

cachebufrowp = &cachebufp[dy * cachebufsize.cx];
for (i = left, dx = x; i < width; i += 4, ++dx) {
backColor = cachebufrowp[dx];
COLORREF last = 0xFFFFFFFF;
if (AAMode == 2 || AAMode == 4) {
alphaR = p[i + 0] / alphatuner;
alphaG = p[i + 1] / alphatuner;
alphaB = p[i + 2] / alphatuner;
alpha = p[i + 3] / alphatuner;
}
else {
// BGR
alphaR = p[i + 2] / alphatuner;
alphaG = p[i + 1] / alphatuner;
alphaB = p[i + 0] / alphatuner;
alpha = p[i + 3] / alphatuner;
}

newColor = mixer(backColor, alphaB, alphaG, alphaR, alpha);
cachebufrowp[dx] = newColor;
}
}
else
for (j = 0, dy = y; j < height; ++j, ++dy) {
if ((unsigned int)dy >= (unsigned int)cachebufsize.cy) continue;

p = bitmap->pitch < 0 ?
&bitmap->buffer[(-bitmap->pitch * bitmap->rows) - bitmap->pitch * j] : // up-flow
&bitmap->buffer[bitmap->pitch * j]; // down-flow

cachebufrowp = &cachebufp[dy * cachebufsize.cx];
for (i = left, dx = x; i < width; i += 4, ++dx) {
backColor = cachebufrowp[dx];
COLORREF last = 0xFFFFFFFF;
if (AAMode == 2 || AAMode == 4) {
alphaR = p[i + 0];
alphaG = p[i + 1];
alphaB = p[i + 2];
alpha = p[i + 3];
}
else {
// BGR
alphaR = p[i + 2];
alphaG = p[i + 1];
alphaB = p[i + 0];
alpha = p[i + 3];
}
newColor = mixer(backColor, alphaB, alphaG, alphaR, alpha);
cachebufrowp[dx] = newColor;
}
}
}

static void FreeTypeDrawBitmapGray(FreeTypeGlyphInfo& FTGInfo, CAlphaBlendColor& ab, int x, int y)
{
int i, j;
Expand Down Expand Up @@ -675,6 +794,9 @@ static void FreeTypeDrawBitmap(
case FT_PIXEL_MODE_LCD:
FreeTypeDrawBitmapPixelModeLCD(FTGInfo, ab, x, y);
break;
case FT_PIXEL_MODE_BGRA:
FreeTypeDrawBitmapPixelModeBGRA(FTGInfo, x, y);
break;
default:
return; // 未対応
}
Expand Down Expand Up @@ -851,6 +973,9 @@ static void FreeTypeDrawBitmapV(FreeTypeGlyphInfo& FTGInfo, CAlphaBlendColor& ab
case FT_PIXEL_MODE_LCD_V:
FreeTypeDrawBitmapPixelModeLCDV(FTGInfo, ab, x, y);
break;
case FT_PIXEL_MODE_BGRA:
FreeTypeDrawBitmapPixelModeBGRA(FTGInfo, x, y);
break;
default:
return; // 未対応
}
Expand Down Expand Up @@ -1497,6 +1622,7 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
FreeTypeFontCache* pftCache = FTInfo.pftCache;
const CFontSettings*& pfs = FTInfo.pfs;
FreeTypeFontInfo*& pfi = FTInfo.pfi;
const bool bLoadColor = pSettings->LoadColorFont();
const bool bGlyphIndex = FTInfo.IsGlyphIndex();
//const bool bSizeOnly = FTInfo.IsSizeOnly();
//const bool bOwnCache = !(FTInfo.font_type.flags & FT_LOAD_RENDER);
Expand Down Expand Up @@ -1626,6 +1752,8 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
freetype_face = FTInfo.GetFace(j); //ヘャハアク�ツカヤモヲfaceidオトハオシハface
//スモマツタエク�ツカヤモヲオトfontsetting
FTInfo.font_type.flags = FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
if (bLoadColor && FT_HAS_COLOR(freetype_face))
FTInfo.font_type.flags |= FT_LOAD_COLOR; // load color font if requested and font supports it
// ヒンティング
//extern CFontSetCache g_fsetcache;
//pfs = g_fsetcache.Get(FTInfo.font_type.face_id);
Expand Down Expand Up @@ -1890,6 +2018,14 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
}
{
CCriticalSectionLock __lock(CCriticalSectionLock::CS_LIBRARY);
if (bLoadColor) {
// use custom API to get color bitmap
if (FT_Glyph_To_BitmapEx(&((*glyph_bitmap)->ft_glyph), render_mode, 0, 1, 1, glyph_index, freetype_face)) {
FT_Done_Ref_Glyph(glyph_bitmap);
nRet = false;
goto gdiexit;
}
} else
if(FT_Glyph_To_Bitmap(&((*glyph_bitmap)->ft_glyph), render_mode, 0, 1)){
FT_Done_Ref_Glyph(glyph_bitmap);
nRet= false;
Expand All @@ -1907,8 +2043,19 @@ BOOL ForEachGetGlyphFT(FreeTypeDrawInfo& FTInfo, LPCTSTR lpString, int cbString,
int dy = clpdx.gety(0); //サテク゚カネ
int dx = clpdx.get(bWidthGDI32 ? gdi32x : cx); //サテソ昮ネ
int left = FT_BitmapGlyph((*glyph_bitmap)->ft_glyph)->left;
if (FTInfo.x + left< FTInfo.xBase)
FTInfo.xBase = FTInfo.x + left; //ネ郢﨧ミラヨキ鈹ヌクコハニシホサヨテオト」ィコマウノキ釚ナ」ゥ」ャ オ鉸トラヨオトニシホサヨテ
if (gdi32x == 0) { // zero width text (most likely a diacritic)
if (FTInfo.x + dx + left < FTInfo.xBase)
FTInfo.xBase = FTInfo.x + dx + left;
//it needs to be drawn at the end of the offset (Windows specific, Windows will "share" half of letter's width to the diacritic)
if (i > 0) {
// we need to update the logical start position of the previous letter to compensate the strange behavior.
*(Dx - 1) = FTInfo.x + dx;
}
}
else {
if (FTInfo.x + left < FTInfo.xBase)
FTInfo.xBase = FTInfo.x + left; //ネ郢﨧ミラヨキ鈹ヌクコハニシホサヨテオト」ィコマウノキ釚ナ」ゥ」ャ オ鉸トラヨオトニシホサヨテ
}

if (lpString < lpEnd - 1) {
FTInfo.x += dx;
Expand Down Expand Up @@ -2602,18 +2749,18 @@ BOOL FreeTypeTextOut(

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

FreeTypeGlyphInfo FTGInfo = {&FTInfo, 0, 0, 0, solid, shadow};
FreeTypeGlyphInfo FTGInfo = {&FTInfo, 0, 0, 0, solid, shadow, pSettings->InvertColor()};
for (int i=0; i<cbString; ++i, ++lpString)
{
WCHAR wch = *lpString;
if (Glyphs[i])
if (Glyphs[i]) // paint text with FreeType
{
FTGInfo.wch = wch;
FTGInfo.FTGlyph = (FT_BitmapGlyph)(Glyphs[i]->ft_glyph);
FTGInfo.AAMode = FTInfo.AAModes[i];
TextOutCallback(FTGInfo);
}
else
else // paint text(bitmap) with gdi
{
int j = i;
FT_DRAW_STATE st= drState[i];
Expand Down
13 changes: 6 additions & 7 deletions hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)

//4
{
#ifdef INFINALITY
// enable infinality exclusive features
FT_initEnv();
#ifdef INFINALITY
// enable infinality exclusive features
FT_initEnv();
#endif
CGdippSettings* pSettings = CGdippSettings::CreateInstance();
if (!pSettings || !pSettings->LoadSettings(instance)) {
Expand All @@ -486,7 +486,6 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
bEnableDW = pSettings->DirectWrite();
}
if (!IsUnload) hook_initinternal(); //イサシモヤリオトト」ソ鮴ヘイサラホコホハツヌ

//5
if (!IsProcessExcluded() && !IsUnload) {
#ifndef _WIN64
Expand Down Expand Up @@ -571,9 +570,9 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved)
delete g_pFTEngine;
}

#ifdef INFINALITY
// enable infinality exclusive features
FT_freeEnv();
#ifdef INFINALITY
// enable infinality exclusive features
FT_freeEnv();
#endif
//if (g_alterGUIFont)
// DeleteObject(g_alterGUIFont);
Expand Down
3 changes: 2 additions & 1 deletion settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ bool CGdippSettings::LoadAppSettings(LPCTSTR lpszFile)

//experimental settings:
m_bEnableClipBoxFix = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ClipBoxFix"), 1, lpszFile);

m_bColorFont = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("ColorFont"), 0, lpszFile);
m_bInvertColor = !!_GetFreeTypeProfileIntFromSection(_T("Experimental"), _T("InvertColor"), 0, lpszFile);
#ifdef INFINALITY
// define some macros
#define INF_INT_ENV(y, def) \
Expand Down
4 changes: 4 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class CGdippSettings

//settings for experimental
bool m_bEnableClipBoxFix;
bool m_bColorFont;
bool m_bInvertColor;


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

0 comments on commit 7520232

Please sign in to comment.