summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxge/ge/cfx_font.cpp (renamed from core/fxge/ge/fx_ge_font.cpp)325
-rw-r--r--core/fxge/ge/fx_ge_text.cpp271
2 files changed, 288 insertions, 308 deletions
diff --git a/core/fxge/ge/fx_ge_font.cpp b/core/fxge/ge/cfx_font.cpp
index cb86429ef6..4aefec8d43 100644
--- a/core/fxge/ge/fx_ge_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -10,6 +10,7 @@
#include "core/fxge/ge/fx_text_int.h"
#include "core/fxge/include/cfx_fontmgr.h"
#include "core/fxge/include/cfx_gemodule.h"
+#include "core/fxge/include/cfx_pathdata.h"
#include "core/fxge/include/cfx_substfont.h"
#include "core/fxge/include/fx_freetype.h"
@@ -17,6 +18,15 @@
namespace {
+typedef struct {
+ FX_BOOL m_bCount;
+ int m_PointCount;
+ FX_PATHPOINT* m_pPoints;
+ int m_CurX;
+ int m_CurY;
+ FX_FLOAT m_CoordUnit;
+} OUTLINE_PARAMS;
+
#ifdef PDF_ENABLE_XFA
unsigned long FTStreamRead(FXFT_Stream stream,
@@ -59,16 +69,161 @@ FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
}
+void Outline_CheckEmptyContour(OUTLINE_PARAMS* param) {
+ if (param->m_PointCount >= 2 &&
+ param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO &&
+ param->m_pPoints[param->m_PointCount - 2].m_PointX ==
+ param->m_pPoints[param->m_PointCount - 1].m_PointX &&
+ param->m_pPoints[param->m_PointCount - 2].m_PointY ==
+ param->m_pPoints[param->m_PointCount - 1].m_PointY) {
+ param->m_PointCount -= 2;
+ }
+ if (param->m_PointCount >= 4 &&
+ param->m_pPoints[param->m_PointCount - 4].m_Flag == FXPT_MOVETO &&
+ param->m_pPoints[param->m_PointCount - 3].m_Flag == FXPT_BEZIERTO &&
+ param->m_pPoints[param->m_PointCount - 3].m_PointX ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+ param->m_pPoints[param->m_PointCount - 3].m_PointY ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointY &&
+ param->m_pPoints[param->m_PointCount - 2].m_PointX ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+ param->m_pPoints[param->m_PointCount - 2].m_PointY ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointY &&
+ param->m_pPoints[param->m_PointCount - 1].m_PointX ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointX &&
+ param->m_pPoints[param->m_PointCount - 1].m_PointY ==
+ param->m_pPoints[param->m_PointCount - 4].m_PointY) {
+ param->m_PointCount -= 4;
+ }
+}
+
+int Outline_MoveTo(const FXFT_Vector* to, void* user) {
+ OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+ if (!param->m_bCount) {
+ Outline_CheckEmptyContour(param);
+ param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_Flag = FXPT_MOVETO;
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
+ if (param->m_PointCount)
+ param->m_pPoints[param->m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
+ }
+ param->m_PointCount++;
+ return 0;
+}
+
+int Outline_LineTo(const FXFT_Vector* to, void* user) {
+ OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+ if (!param->m_bCount) {
+ param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_Flag = FXPT_LINETO;
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
+ }
+ param->m_PointCount++;
+ return 0;
+}
+
+int Outline_ConicTo(const FXFT_Vector* control,
+ const FXFT_Vector* to,
+ void* user) {
+ OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+ if (!param->m_bCount) {
+ param->m_pPoints[param->m_PointCount].m_PointX =
+ (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
+ param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_PointY =
+ (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) /
+ param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
+ param->m_pPoints[param->m_PointCount + 1].m_PointX =
+ (control->x + (to->x - control->x) / 3) / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 1].m_PointY =
+ (control->y + (to->y - control->y) / 3) / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
+ param->m_pPoints[param->m_PointCount + 2].m_PointX =
+ to->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 2].m_PointY =
+ to->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
+ }
+ param->m_PointCount += 3;
+ return 0;
+}
+
+int Outline_CubicTo(const FXFT_Vector* control1,
+ const FXFT_Vector* control2,
+ const FXFT_Vector* to,
+ void* user) {
+ OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+ if (!param->m_bCount) {
+ param->m_pPoints[param->m_PointCount].m_PointX =
+ control1->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_PointY =
+ control1->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
+ param->m_pPoints[param->m_PointCount + 1].m_PointX =
+ control2->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 1].m_PointY =
+ control2->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
+ param->m_pPoints[param->m_PointCount + 2].m_PointX =
+ to->x / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 2].m_PointY =
+ to->y / param->m_CoordUnit;
+ param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
+ param->m_CurX = to->x;
+ param->m_CurY = to->y;
+ }
+ param->m_PointCount += 3;
+ return 0;
+}
+
} // namespace
+const char CFX_Font::s_AngleSkew[] = {
+ 0, 2, 3, 5, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 25,
+ 27, 29, 31, 32, 34, 36, 38, 40, 42, 45, 47, 49, 51, 53, 55,
+};
+
+const uint8_t CFX_Font::s_WeightPow[] = {
+ 0, 3, 6, 7, 8, 9, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, 37,
+ 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42,
+ 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47,
+ 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50,
+ 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53,
+};
+
+const uint8_t CFX_Font::s_WeightPow_11[] = {
+ 0, 4, 7, 8, 9, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40, 41,
+ 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46,
+ 46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52,
+ 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55,
+ 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58,
+};
+
+const uint8_t CFX_Font::s_WeightPow_SHIFTJIS[] = {
+ 0, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21,
+ 22, 24, 26, 28, 30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48,
+ 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53,
+ 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56,
+ 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
+ 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60,
+};
+
CFX_Font::CFX_Font()
+ :
#ifdef PDF_ENABLE_XFA
- : m_bLogic(FALSE),
+ m_bLogic(FALSE),
m_pOwnedStream(nullptr),
- m_Face(nullptr),
-#else
- : m_Face(nullptr),
#endif // PDF_ENABLE_XFA
+ m_Face(nullptr),
m_pFontData(nullptr),
m_pGsubData(nullptr),
m_dwSize(0),
@@ -124,11 +279,10 @@ CFX_Font::~CFX_Font() {
FXFT_Clear_Face_External_Stream(m_Face);
}
#endif // PDF_ENABLE_XFA
- if (m_bEmbedded) {
+ if (m_bEmbedded)
DeleteFace();
- } else {
+ else
CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
- }
}
#ifdef PDF_ENABLE_XFA
FX_Free(m_pOwnedStream);
@@ -186,18 +340,15 @@ FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile,
#endif // PDF_ENABLE_XFA
int CFX_Font::GetGlyphWidth(uint32_t glyph_index) {
- if (!m_Face) {
+ if (!m_Face)
return 0;
- }
- if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) {
+ if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM))
AdjustMMParams(glyph_index, 0, 0);
- }
int err = FXFT_Load_Glyph(
m_Face, glyph_index,
FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- if (err) {
+ if (err)
return 0;
- }
int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
FXFT_Get_Glyph_HoriAdvance(m_Face));
return width;
@@ -239,20 +390,17 @@ FX_BOOL CFX_Font::GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox) {
if (FXFT_Is_Face_Tricky(m_Face)) {
int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72);
- if (error) {
+ if (error)
return FALSE;
- }
error = FXFT_Load_Glyph(m_Face, glyph_index,
FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- if (error) {
+ if (error)
return FALSE;
- }
FXFT_BBox cbox;
FT_Glyph glyph;
error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph);
- if (error) {
+ if (error)
return FALSE;
- }
FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem,
pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem;
@@ -267,12 +415,10 @@ FX_BOOL CFX_Font::GetGlyphBBox(uint32_t glyph_index, FX_RECT& bbox) {
bbox.top = cbox.yMax * 1000 / pixel_size_y;
bbox.bottom = cbox.yMin * 1000 / pixel_size_y;
}
- if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) {
+ if (bbox.top > FXFT_Get_Face_Ascender(m_Face))
bbox.top = FXFT_Get_Face_Ascender(m_Face);
- }
- if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) {
+ if (bbox.bottom < FXFT_Get_Face_Descender(m_Face))
bbox.bottom = FXFT_Get_Face_Descender(m_Face);
- }
FT_Done_Glyph(glyph);
return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0;
}
@@ -308,9 +454,8 @@ FX_BOOL CFX_Font::IsItalic() const {
if (!ret) {
CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face));
str.MakeLower();
- if (str.Find("italic") != -1) {
+ if (str.Find("italic") != -1)
ret = TRUE;
- }
}
return ret;
}
@@ -338,36 +483,32 @@ CFX_ByteString CFX_Font::GetPsName() const {
}
CFX_ByteString CFX_Font::GetFamilyName() const {
- if (!m_Face && !m_pSubstFont) {
+ if (!m_Face && !m_pSubstFont)
return CFX_ByteString();
- }
- if (m_Face) {
+ if (m_Face)
return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face));
- }
return m_pSubstFont->m_Family;
}
+
CFX_ByteString CFX_Font::GetFaceName() const {
- if (!m_Face && !m_pSubstFont) {
+ if (!m_Face && !m_pSubstFont)
return CFX_ByteString();
- }
if (m_Face) {
CFX_ByteString facename;
CFX_ByteString style = CFX_ByteString(FXFT_Get_Face_Style_Name(m_Face));
facename = GetFamilyName();
- if (facename.IsEmpty()) {
+ if (facename.IsEmpty())
facename = "Untitled";
- }
- if (!style.IsEmpty() && style != "Regular") {
+ if (!style.IsEmpty() && style != "Regular")
facename += " " + style;
- }
return facename;
}
return m_pSubstFont->m_Family;
}
+
FX_BOOL CFX_Font::GetBBox(FX_RECT& bbox) {
- if (!m_Face) {
+ if (!m_Face)
return FALSE;
- }
int em = FXFT_Get_Face_UnitsPerEM(m_Face);
if (em == 0) {
bbox.left = FXFT_Get_Face_xMin(m_Face);
@@ -414,3 +555,113 @@ int CFX_Font::GetULthickness() const {
return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
FXFT_Get_Face_UnderLineThickness(m_Face));
}
+
+void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
+ FXFT_MM_Var pMasters = nullptr;
+ FXFT_Get_MM_Var(m_Face, &pMasters);
+ if (!pMasters)
+ return;
+ long coords[2];
+ if (weight == 0)
+ coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536;
+ else
+ coords[0] = weight;
+ if (dest_width == 0) {
+ coords[1] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+ } else {
+ int min_param = FXFT_Get_MM_Axis_Min(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+ int max_param = FXFT_Get_MM_Axis_Max(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
+ coords[1] = min_param;
+ FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+ FXFT_Load_Glyph(m_Face, glyph_index,
+ FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ int min_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
+ FXFT_Get_Face_UnitsPerEM(m_Face);
+ coords[1] = max_param;
+ FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+ FXFT_Load_Glyph(m_Face, glyph_index,
+ FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
+ FXFT_Get_Face_UnitsPerEM(m_Face);
+ if (max_width == min_width) {
+ FXFT_Free(m_Face, pMasters);
+ return;
+ }
+ int param = min_param +
+ (max_param - min_param) * (dest_width - min_width) /
+ (max_width - min_width);
+ coords[1] = param;
+ }
+ FXFT_Free(m_Face, pMasters);
+ FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
+}
+
+CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
+ if (!m_Face)
+ return nullptr;
+ FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
+ FXFT_Matrix ft_matrix = {65536, 0, 0, 65536};
+ if (m_pSubstFont) {
+ if (m_pSubstFont->m_ItalicAngle) {
+ int skew = m_pSubstFont->m_ItalicAngle;
+ // |skew| is nonpositive so |-skew| is used as the index. We need to make
+ // sure |skew| != INT_MIN since -INT_MIN is undefined.
+ if (skew <= 0 && skew != std::numeric_limits<int>::min() &&
+ static_cast<size_t>(-skew) < kAngleSkewArraySize) {
+ skew = -s_AngleSkew[-skew];
+ } else {
+ skew = -58;
+ }
+ if (m_bVertical)
+ ft_matrix.yx += ft_matrix.yy * skew / 100;
+ else
+ ft_matrix.xy -= ft_matrix.xx * skew / 100;
+ }
+ if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
+ AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
+ }
+ }
+ ScopedFontTransform scoped_transform(m_Face, &ft_matrix);
+ int load_flags = FXFT_LOAD_NO_BITMAP;
+ if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face))
+ load_flags |= FT_LOAD_NO_HINTING;
+ if (FXFT_Load_Glyph(m_Face, glyph_index, load_flags))
+ return nullptr;
+ if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
+ m_pSubstFont->m_Weight > 400) {
+ uint32_t index = (m_pSubstFont->m_Weight - 400) / 10;
+ index = std::min(index, static_cast<uint32_t>(kWeightPowArraySize - 1));
+ int level = 0;
+ if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET)
+ level = s_WeightPow_SHIFTJIS[index] * 2 * 65536 / 36655;
+ else
+ level = s_WeightPow[index] * 2;
+ FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
+ }
+ FXFT_Outline_Funcs funcs;
+ funcs.move_to = Outline_MoveTo;
+ funcs.line_to = Outline_LineTo;
+ funcs.conic_to = Outline_ConicTo;
+ funcs.cubic_to = Outline_CubicTo;
+ funcs.shift = 0;
+ funcs.delta = 0;
+ OUTLINE_PARAMS params;
+ params.m_bCount = TRUE;
+ params.m_PointCount = 0;
+ FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
+ if (params.m_PointCount == 0)
+ return nullptr;
+ CFX_PathData* pPath = new CFX_PathData;
+ pPath->SetPointCount(params.m_PointCount);
+ params.m_bCount = FALSE;
+ params.m_PointCount = 0;
+ params.m_pPoints = pPath->GetPoints();
+ params.m_CurX = params.m_CurY = 0;
+ params.m_CoordUnit = 64 * 64.0;
+ FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
+ Outline_CheckEmptyContour(&params);
+ pPath->TrimPoints(params.m_PointCount);
+ if (params.m_PointCount)
+ pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
+ return pPath;
+}
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp
index b81c1ba8f1..415711f0cd 100644
--- a/core/fxge/ge/fx_ge_text.cpp
+++ b/core/fxge/ge/fx_ge_text.cpp
@@ -104,277 +104,6 @@ CFX_SizeGlyphCache::~CFX_SizeGlyphCache() {
m_GlyphMap.clear();
}
-#define CONTRAST_RAMP_STEP 1
-void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
- FXFT_MM_Var pMasters = nullptr;
- FXFT_Get_MM_Var(m_Face, &pMasters);
- if (!pMasters) {
- return;
- }
- long coords[2];
- if (weight == 0) {
- coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536;
- } else {
- coords[0] = weight;
- }
- if (dest_width == 0) {
- coords[1] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
- } else {
- int min_param = FXFT_Get_MM_Axis_Min(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
- int max_param = FXFT_Get_MM_Axis_Max(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
- coords[1] = min_param;
- (void)FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
- (void)FXFT_Load_Glyph(
- m_Face, glyph_index,
- FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- int min_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
- FXFT_Get_Face_UnitsPerEM(m_Face);
- coords[1] = max_param;
- (void)FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
- (void)FXFT_Load_Glyph(
- m_Face, glyph_index,
- FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- int max_width = FXFT_Get_Glyph_HoriAdvance(m_Face) * 1000 /
- FXFT_Get_Face_UnitsPerEM(m_Face);
- if (max_width == min_width) {
- FXFT_Free(m_Face, pMasters);
- return;
- }
- int param = min_param +
- (max_param - min_param) * (dest_width - min_width) /
- (max_width - min_width);
- coords[1] = param;
- }
- FXFT_Free(m_Face, pMasters);
- FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
-}
-const char CFX_Font::s_AngleSkew[] = {
- 0, 2, 3, 5, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 25,
- 27, 29, 31, 32, 34, 36, 38, 40, 42, 45, 47, 49, 51, 53, 55,
-};
-const uint8_t CFX_Font::s_WeightPow[] = {
- 0, 3, 6, 7, 8, 9, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22,
- 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, 37,
- 37, 37, 38, 38, 38, 39, 39, 39, 40, 40, 40, 41, 41, 41, 42, 42, 42,
- 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47,
- 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 50,
- 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53,
-};
-const uint8_t CFX_Font::s_WeightPow_11[] = {
- 0, 4, 7, 8, 9, 10, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 39, 40, 40, 41,
- 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46,
- 46, 43, 47, 47, 48, 48, 48, 48, 45, 50, 50, 50, 46, 51, 51, 51, 52,
- 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 55,
- 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58,
-};
-const uint8_t CFX_Font::s_WeightPow_SHIFTJIS[] = {
- 0, 0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21,
- 22, 24, 26, 28, 30, 32, 33, 35, 37, 39, 41, 43, 45, 48, 48, 48, 48,
- 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53,
- 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56,
- 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58,
- 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60,
-};
-typedef struct {
- FX_BOOL m_bCount;
- int m_PointCount;
- FX_PATHPOINT* m_pPoints;
- int m_CurX;
- int m_CurY;
- FX_FLOAT m_CoordUnit;
-} OUTLINE_PARAMS;
-void _Outline_CheckEmptyContour(OUTLINE_PARAMS* param) {
- if (param->m_PointCount >= 2 &&
- param->m_pPoints[param->m_PointCount - 2].m_Flag == FXPT_MOVETO &&
- param->m_pPoints[param->m_PointCount - 2].m_PointX ==
- param->m_pPoints[param->m_PointCount - 1].m_PointX &&
- param->m_pPoints[param->m_PointCount - 2].m_PointY ==
- param->m_pPoints[param->m_PointCount - 1].m_PointY) {
- param->m_PointCount -= 2;
- }
- if (param->m_PointCount >= 4 &&
- param->m_pPoints[param->m_PointCount - 4].m_Flag == FXPT_MOVETO &&
- param->m_pPoints[param->m_PointCount - 3].m_Flag == FXPT_BEZIERTO &&
- param->m_pPoints[param->m_PointCount - 3].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 3].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY &&
- param->m_pPoints[param->m_PointCount - 2].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 2].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY &&
- param->m_pPoints[param->m_PointCount - 1].m_PointX ==
- param->m_pPoints[param->m_PointCount - 4].m_PointX &&
- param->m_pPoints[param->m_PointCount - 1].m_PointY ==
- param->m_pPoints[param->m_PointCount - 4].m_PointY) {
- param->m_PointCount -= 4;
- }
-}
-extern "C" {
-static int _Outline_MoveTo(const FXFT_Vector* to, void* user) {
- OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- _Outline_CheckEmptyContour(param);
- param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Flag = FXPT_MOVETO;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- if (param->m_PointCount) {
- param->m_pPoints[param->m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
- }
- }
- param->m_PointCount++;
- return 0;
-}
-};
-extern "C" {
-static int _Outline_LineTo(const FXFT_Vector* to, void* user) {
- OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX = to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY = to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Flag = FXPT_LINETO;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount++;
- return 0;
-}
-};
-extern "C" {
-static int _Outline_ConicTo(const FXFT_Vector* control,
- const FXFT_Vector* to,
- void* user) {
- OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX =
- (param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
- param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY =
- (param->m_CurY + (control->y - param->m_CurY) * 2 / 3) /
- param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
- param->m_pPoints[param->m_PointCount + 1].m_PointX =
- (control->x + (to->x - control->x) / 3) / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_PointY =
- (control->y + (to->y - control->y) / 3) / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
- param->m_pPoints[param->m_PointCount + 2].m_PointX =
- to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_PointY =
- to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount += 3;
- return 0;
-}
-};
-extern "C" {
-static int _Outline_CubicTo(const FXFT_Vector* control1,
- const FXFT_Vector* control2,
- const FXFT_Vector* to,
- void* user) {
- OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
- if (!param->m_bCount) {
- param->m_pPoints[param->m_PointCount].m_PointX =
- control1->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_PointY =
- control1->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount].m_Flag = FXPT_BEZIERTO;
- param->m_pPoints[param->m_PointCount + 1].m_PointX =
- control2->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_PointY =
- control2->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 1].m_Flag = FXPT_BEZIERTO;
- param->m_pPoints[param->m_PointCount + 2].m_PointX =
- to->x / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_PointY =
- to->y / param->m_CoordUnit;
- param->m_pPoints[param->m_PointCount + 2].m_Flag = FXPT_BEZIERTO;
- param->m_CurX = to->x;
- param->m_CurY = to->y;
- }
- param->m_PointCount += 3;
- return 0;
-}
-};
-CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
- if (!m_Face) {
- return nullptr;
- }
- FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
- FXFT_Matrix ft_matrix = {65536, 0, 0, 65536};
- if (m_pSubstFont) {
- if (m_pSubstFont->m_ItalicAngle) {
- int skew = m_pSubstFont->m_ItalicAngle;
- // |skew| is nonpositive so |-skew| is used as the index. We need to make
- // sure |skew| != INT_MIN since -INT_MIN is undefined.
- if (skew <= 0 && skew != std::numeric_limits<int>::min() &&
- static_cast<size_t>(-skew) < kAngleSkewArraySize) {
- skew = -s_AngleSkew[-skew];
- } else {
- skew = -58;
- }
- if (m_bVertical)
- ft_matrix.yx += ft_matrix.yy * skew / 100;
- else
- ft_matrix.xy -= ft_matrix.xx * skew / 100;
- }
- if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
- AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
- }
- }
- ScopedFontTransform scoped_transform(m_Face, &ft_matrix);
- int load_flags = FXFT_LOAD_NO_BITMAP;
- if (!(m_Face->face_flags & FT_FACE_FLAG_SFNT) || !FT_IS_TRICKY(m_Face)) {
- load_flags |= FT_LOAD_NO_HINTING;
- }
- if (FXFT_Load_Glyph(m_Face, glyph_index, load_flags))
- return nullptr;
- if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) &&
- m_pSubstFont->m_Weight > 400) {
- uint32_t index = (m_pSubstFont->m_Weight - 400) / 10;
- index = std::min(index, static_cast<uint32_t>(kWeightPowArraySize - 1));
- int level = 0;
- if (m_pSubstFont->m_Charset == FXFONT_SHIFTJIS_CHARSET)
- level = s_WeightPow_SHIFTJIS[index] * 2 * 65536 / 36655;
- else
- level = s_WeightPow[index] * 2;
- FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
- }
- FXFT_Outline_Funcs funcs;
- funcs.move_to = _Outline_MoveTo;
- funcs.line_to = _Outline_LineTo;
- funcs.conic_to = _Outline_ConicTo;
- funcs.cubic_to = _Outline_CubicTo;
- funcs.shift = 0;
- funcs.delta = 0;
- OUTLINE_PARAMS params;
- params.m_bCount = TRUE;
- params.m_PointCount = 0;
- FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
- if (params.m_PointCount == 0) {
- return nullptr;
- }
- CFX_PathData* pPath = new CFX_PathData;
- pPath->SetPointCount(params.m_PointCount);
- params.m_bCount = FALSE;
- params.m_PointCount = 0;
- params.m_pPoints = pPath->GetPoints();
- params.m_CurX = params.m_CurY = 0;
- params.m_CoordUnit = 64 * 64.0;
- FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
- _Outline_CheckEmptyContour(&params);
- pPath->TrimPoints(params.m_PointCount);
- if (params.m_PointCount) {
- pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
- }
- return pPath;
-}
void _CFX_UniqueKeyGen::Generate(int count, ...) {
va_list argList;
va_start(argList, count);