From 3f3b45cc74b0499912409f766a595945dbbfc4c5 Mon Sep 17 00:00:00 2001 From: John Abd-El-Malek Date: Fri, 23 May 2014 17:28:10 -0700 Subject: Convert all line endings to LF. --- core/include/fxge/fx_dib.h | 1212 ++++++++++++++++---------------- core/include/fxge/fx_font.h | 856 +++++++++++------------ core/include/fxge/fx_freetype.h | 288 ++++---- core/include/fxge/fx_ge.h | 1466 +++++++++++++++++++-------------------- core/include/fxge/fx_ge_apple.h | 52 +- core/include/fxge/fx_ge_win32.h | 210 +++--- 6 files changed, 2042 insertions(+), 2042 deletions(-) (limited to 'core/include/fxge') diff --git a/core/include/fxge/fx_dib.h b/core/include/fxge/fx_dib.h index 7aa3bf8d10..957a957043 100644 --- a/core/include/fxge/fx_dib.h +++ b/core/include/fxge/fx_dib.h @@ -1,606 +1,606 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _FPDF_DIB_H_ -#define _FPDF_DIB_H_ -#ifndef _FXCRT_EXTENSION_ -#include "../fxcrt/fx_ext.h" -#endif -enum FXDIB_Format { - FXDIB_Invalid = 0, - FXDIB_1bppMask = 0x101, - FXDIB_1bppRgb = 0x001, - FXDIB_1bppCmyk = 0x401, - FXDIB_8bppMask = 0x108, - FXDIB_8bppRgb = 0x008, - FXDIB_8bppRgba = 0x208, - FXDIB_8bppCmyk = 0x408, - FXDIB_8bppCmyka = 0x608, - FXDIB_Rgb = 0x018, - FXDIB_Rgba = 0x218, - FXDIB_Rgb32 = 0x020, - FXDIB_Argb = 0x220, - FXDIB_Cmyk = 0x420, - FXDIB_Cmyka = 0x620, -}; -enum FXDIB_Channel { - FXDIB_Red = 1, - FXDIB_Green, - FXDIB_Blue, - FXDIB_Cyan, - FXDIB_Magenta, - FXDIB_Yellow, - FXDIB_Black, - FXDIB_Alpha -}; -#define FXDIB_DOWNSAMPLE 0x04 -#define FXDIB_INTERPOL 0x20 -#define FXDIB_BICUBIC_INTERPOL 0x80 -#define FXDIB_NOSMOOTH 0x100 -#define FXDIB_PALETTE_LOC 0x01 -#define FXDIB_PALETTE_WIN 0x02 -#define FXDIB_PALETTE_MAC 0x04 -#define FXDIB_BLEND_NORMAL 0 -#define FXDIB_BLEND_MULTIPLY 1 -#define FXDIB_BLEND_SCREEN 2 -#define FXDIB_BLEND_OVERLAY 3 -#define FXDIB_BLEND_DARKEN 4 -#define FXDIB_BLEND_LIGHTEN 5 - -#define FXDIB_BLEND_COLORDODGE 6 -#define FXDIB_BLEND_COLORBURN 7 -#define FXDIB_BLEND_HARDLIGHT 8 -#define FXDIB_BLEND_SOFTLIGHT 9 -#define FXDIB_BLEND_DIFFERENCE 10 -#define FXDIB_BLEND_EXCLUSION 11 -#define FXDIB_BLEND_NONSEPARABLE 21 -#define FXDIB_BLEND_HUE 21 -#define FXDIB_BLEND_SATURATION 22 -#define FXDIB_BLEND_COLOR 23 -#define FXDIB_BLEND_LUMINOSITY 24 -#define FXDIB_BLEND_UNSUPPORTED -1 -typedef FX_DWORD FX_ARGB; -typedef FX_DWORD FX_COLORREF; -typedef FX_DWORD FX_CMYK; -class CFX_ClipRgn; -class CFX_DIBSource; -class CFX_DIBitmap; -#define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) -#define FXSYS_GetRValue(rgb) ((rgb) & 0xff) -#define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff) -#define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff) -#define FX_CCOLOR(val) (255-(val)) -#define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k)) -#define FXSYS_GetCValue(cmyk) ((FX_BYTE)((cmyk) >> 24) & 0xff) -#define FXSYS_GetMValue(cmyk) ((FX_BYTE)((cmyk) >> 16) & 0xff) -#define FXSYS_GetYValue(cmyk) ((FX_BYTE)((cmyk) >> 8) & 0xff) -#define FXSYS_GetKValue(cmyk) ((FX_BYTE)(cmyk) & 0xff) -void CmykDecode(FX_CMYK cmyk, int& c, int& m, int& y, int& k); -inline FX_CMYK CmykEncode(int c, int m, int y, int k) -{ - return (c << 24) | (m << 16) | (y << 8) | k; -} -void ArgbDecode(FX_ARGB argb, int& a, int& r, int&g, int& b); -void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb); -inline FX_ARGB ArgbEncode(int a, int r, int g, int b) -{ - return (a << 24) | (r << 16) | (g << 8) | b; -} -FX_ARGB ArgbEncode(int a, FX_COLORREF rgb); -#define FXARGB_A(argb) ((FX_BYTE)((argb) >> 24)) -#define FXARGB_R(argb) ((FX_BYTE)((argb) >> 16)) -#define FXARGB_G(argb) ((FX_BYTE)((argb) >> 8)) -#define FXARGB_B(argb) ((FX_BYTE)(argb)) -#define FXARGB_MAKE(a,r,g,b) (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) -#define FXARGB_MUL_ALPHA(argb, alpha) (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb) & 0xffffff)) -#define FXRGB2GRAY(r,g,b) (((b) * 11 + (g) * 59 + (r) * 30) / 100) -#define FXCMYK2GRAY(c,m,y,k) (((255-(c)) * (255-(k)) * 30 + (255-(m)) * (255-(k)) * 59 + (255-(y)) * (255-(k)) * 11) / 25500) -#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) (((backdrop) * (255-(source_alpha)) + (source)*(source_alpha))/255) -#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest)*(src)/255) -#define FXCMYK_GETDIB(p) ((((FX_LPBYTE)(p))[0] << 24 | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | ((FX_LPBYTE)(p))[3])) -#define FXCMYK_SETDIB(p, cmyk) ((FX_LPBYTE)(p))[0] = (FX_BYTE)((cmyk) >> 24), \ - ((FX_LPBYTE)(p))[1] = (FX_BYTE)((cmyk) >> 16), \ - ((FX_LPBYTE)(p))[2] = (FX_BYTE)((cmyk) >> 8), \ - ((FX_LPBYTE)(p))[3] = (FX_BYTE)(cmyk)) -#define FXARGB_GETDIB(p) (((FX_LPBYTE)(p))[0]) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[3] << 24) -#define FXARGB_SETDIB(p, argb) ((FX_LPBYTE)(p))[0] = (FX_BYTE)(argb), \ - ((FX_LPBYTE)(p))[1] = (FX_BYTE)((argb) >> 8), \ - ((FX_LPBYTE)(p))[2] = (FX_BYTE)((argb) >> 16), \ - ((FX_LPBYTE)(p))[3] = (FX_BYTE)((argb) >> 24) -#define FXARGB_COPY(dest, src) *(FX_LPBYTE)(dest) = *(FX_LPBYTE)(src), \ - *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ - *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)+2), \ - *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3) -#define FXCMYK_COPY(dest, src) *(FX_LPBYTE)(dest) = *(FX_LPBYTE)(src), \ - *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ - *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)+2), \ - *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3) -#define FXARGB_SETRGBORDERDIB(p, argb) ((FX_LPBYTE)(p))[3] = (FX_BYTE)(argb>>24), \ - ((FX_LPBYTE)(p))[0] = (FX_BYTE)((argb) >> 16), \ - ((FX_LPBYTE)(p))[1] = (FX_BYTE)((argb) >> 8), \ - ((FX_LPBYTE)(p))[2] = (FX_BYTE)(argb) -#define FXARGB_GETRGBORDERDIB(p) (((FX_LPBYTE)(p))[2]) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0] << 16) | (((FX_LPBYTE)(p))[3] << 24) -#define FXARGB_RGBORDERCOPY(dest, src) *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3), \ - *(FX_LPBYTE)(dest) = *((FX_LPBYTE)(src)+2), \ - *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ - *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)) -#define FXARGB_TODIB(argb) (argb) -#define FXCMYK_TODIB(cmyk) ((FX_BYTE)((cmyk) >> 24) | ((FX_BYTE)((cmyk) >> 16)) << 8 | ((FX_BYTE)((cmyk) >> 8)) << 16 | ((FX_BYTE)(cmyk) << 24)) -#define FXARGB_TOBGRORDERDIB(argb) ((FX_BYTE)(argb>>16) | ((FX_BYTE)(argb>>8)) << 8 | ((FX_BYTE)(argb)) << 16 | ((FX_BYTE)(argb>>24) << 24)) -#define FXGETFLAG_COLORTYPE(flag) (FX_BYTE)((flag)>>8) -#define FXGETFLAG_ALPHA_FILL(flag) (FX_BYTE)(flag) -#define FXGETFLAG_ALPHA_STROKE(flag) (FX_BYTE)((flag)>>16) -#define FXSETFLAG_COLORTYPE(flag, val) flag = (((val)<<8)|(flag&0xffff00ff)) -#define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val)|(flag&0xffffff00)) -#define FXSETFLAG_ALPHA_STROKE(flag, val) flag = (((val)<<16)|(flag&0xff00ffff)) -class CFX_DIBSource : public CFX_Object -{ -public: - - virtual ~CFX_DIBSource(); - - - - int GetWidth() const - { - return m_Width; - } - - int GetHeight() const - { - return m_Height; - } - - FXDIB_Format GetFormat() const - { - return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); - } - - FX_DWORD GetPitch() const - { - return m_Pitch; - } - - FX_DWORD* GetPalette() const - { - return m_pPalette; - } - - - - virtual FX_LPBYTE GetBuffer() const - { - return NULL; - } - - virtual FX_LPCBYTE GetScanline(int line) const = 0; - - virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const - { - return FALSE; - } - - virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const = 0; - - virtual void SetDownSampleSize(int width, int height) const {} - - int GetBPP() const - { - return m_bpp; - } - - FX_BOOL IsAlphaMask() const - { - return m_AlphaFlag == 1; - } - - FX_BOOL HasAlpha() const - { - return m_AlphaFlag & 2 ? TRUE : FALSE; - } - - FX_BOOL IsOpaqueImage() const - { - return !(m_AlphaFlag & 3); - } - - FX_BOOL IsCmykImage() const - { - return m_AlphaFlag & 4 ? TRUE : FALSE; - } - - - - int GetPaletteSize() const - { - return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); - } - - FX_DWORD GetPaletteEntry(int index) const; - - void SetPaletteEntry(int index, FX_DWORD color); - FX_DWORD GetPaletteArgb(int index) const - { - return GetPaletteEntry(index); - } - void SetPaletteArgb(int index, FX_DWORD color) - { - SetPaletteEntry(index, color); - } - - void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); - - - CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; - - CFX_DIBitmap* CloneConvert(FXDIB_Format format, const FX_RECT* pClip = NULL, void* pIccTransform = NULL) const; - - CFX_DIBitmap* StretchTo(int dest_width, int dest_height, FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; - - - CFX_DIBitmap* TransformTo(const CFX_AffineMatrix* pMatrix, int& left, int &top, - FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; - - CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; - - FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip = NULL); - - CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_RECT* pClip = NULL) const; - - CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; - - void GetOverlapRect(int& dest_left, int& dest_top, int& width, int& height, int src_width, - int src_height, int& src_left, int& src_top, const CFX_ClipRgn* pClipRgn); - - CFX_DIBitmap* m_pAlphaMask; -protected: - - CFX_DIBSource(); - - int m_Width; - - int m_Height; - - int m_bpp; - - FX_DWORD m_AlphaFlag; - - FX_DWORD m_Pitch; - - FX_DWORD* m_pPalette; - - void BuildPalette(); - - FX_BOOL BuildAlphaMask(); - - int FindPalette(FX_DWORD color) const; - - void GetPalette(FX_DWORD* pal, int alpha) const; -}; -class CFX_DIBitmap : public CFX_DIBSource -{ -public: - - virtual ~CFX_DIBitmap(); - - CFX_DIBitmap(); - - CFX_DIBitmap(const CFX_DIBitmap& src); - - FX_BOOL Create(int width, int height, FXDIB_Format format, FX_LPBYTE pBuffer = NULL, int pitch = 0); - - FX_BOOL Copy(const CFX_DIBSource* pSrc); - - virtual FX_LPBYTE GetBuffer() const - { - return m_pBuffer; - } - - virtual FX_LPCBYTE GetScanline(int line) const - { - return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL; - } - - virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; - - void TakeOver(CFX_DIBitmap* pSrcBitmap); - - FX_BOOL ConvertFormat(FXDIB_Format format, void* pIccTransform = NULL); - - void Clear(FX_DWORD color); - - FX_DWORD GetPixel(int x, int y) const; - - void SetPixel(int x, int y, FX_DWORD color); - - FX_BOOL LoadChannel(FXDIB_Channel destChannel, const CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel); - - FX_BOOL LoadChannel(FXDIB_Channel destChannel, int value); - - FX_BOOL MultiplyAlpha(int alpha); - - FX_BOOL MultiplyAlpha(const CFX_DIBSource* pAlphaMask); - - FX_BOOL TransferBitmap(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform = NULL); - - FX_BOOL CompositeBitmap(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, - int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, void* pIccTransform = NULL); - - FX_BOOL TransferMask(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL CompositeMask(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, - int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL CompositeRect(int dest_left, int dest_top, int width, int height, FX_DWORD color, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor); - - FX_BOOL DitherFS(const FX_DWORD* pPalette, int pal_size, const FX_RECT* pRect = NULL); -protected: - - FX_LPBYTE m_pBuffer; - - FX_BOOL m_bExtBuf; - - FX_BOOL GetGrayData(void* pIccTransform = NULL); -}; -class CFX_DIBExtractor : public CFX_Object -{ -public: - - CFX_DIBExtractor(const CFX_DIBSource* pSrc); - - ~CFX_DIBExtractor(); - - operator CFX_DIBitmap*() - { - return m_pBitmap; - } -private: - - CFX_DIBitmap* m_pBitmap; -}; -typedef CFX_CountRef CFX_DIBitmapRef; -class CFX_FilteredDIB : public CFX_DIBSource -{ -public: - - CFX_FilteredDIB(); - - ~CFX_FilteredDIB(); - - void LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc = FALSE); - - virtual FXDIB_Format GetDestFormat() = 0; - - virtual FX_DWORD* GetDestPalette() = 0; - - - virtual void TranslateScanline(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf) const = 0; - - virtual void TranslateDownSamples(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf, int pixels, int Bpp) const = 0; -protected: - virtual FX_LPCBYTE GetScanline(int line) const; - virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; - - const CFX_DIBSource* m_pSrc; - - FX_BOOL m_bAutoDropSrc; - - FX_LPBYTE m_pScanline; -}; -class IFX_ScanlineComposer -{ -public: - - virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha = NULL) = 0; - - - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette) = 0; -}; -class CFX_ScanlineCompositor : public CFX_Object -{ -public: - - CFX_ScanlineCompositor(); - - ~CFX_ScanlineCompositor(); - - FX_BOOL Init(FXDIB_Format dest_format, FXDIB_Format src_format, FX_INT32 width, FX_DWORD* pSrcPalette, - FX_DWORD mask_color, int blend_type, FX_BOOL bClip, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); - - - void CompositeRgbBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan, - FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); - - - void CompositePalBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan, - FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); - - - void CompositeByteMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan, - FX_LPBYTE dst_extra_alpha = NULL); - - - void CompositeBitMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan, - FX_LPBYTE dst_extra_alpha = NULL); -protected: - int m_Transparency; - FXDIB_Format m_SrcFormat, - m_DestFormat; - FX_DWORD* m_pSrcPalette; - - int m_MaskAlpha, - m_MaskRed, - m_MaskGreen, - m_MaskBlue, - m_MaskBlack; - int m_BlendType; - void* m_pIccTransform; - FX_LPBYTE m_pCacheScanline; - int m_CacheSize; - FX_BOOL m_bRgbByteOrder; -}; -class CFX_BitmapComposer : public IFX_ScanlineComposer, public CFX_Object -{ -public: - - CFX_BitmapComposer(); - - ~CFX_BitmapComposer(); - - - void Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha, - FX_DWORD mask_color, FX_RECT& dest_rect, FX_BOOL bVertical, - FX_BOOL bFlipX, FX_BOOL bFlipY, FX_BOOL bRgbByteOrder = FALSE, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); - - - virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha); -protected: - - void DoCompose(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int dest_width, FX_LPCBYTE clip_scan, - FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); - CFX_DIBitmap* m_pBitmap; - const CFX_ClipRgn* m_pClipRgn; - FXDIB_Format m_SrcFormat; - int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha; - FX_DWORD m_MaskColor; - const CFX_DIBitmap* m_pClipMask; - CFX_ScanlineCompositor m_Compositor; - FX_BOOL m_bVertical, m_bFlipX, m_bFlipY; - int m_AlphaFlag; - void* m_pIccTransform; - FX_BOOL m_bRgbByteOrder; - int m_BlendType; - void ComposeScanlineV(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha = NULL); - FX_LPBYTE m_pScanlineV, m_pClipScanV, m_pAddClipScan, m_pScanlineAlphaV; -}; -class CFX_BitmapStorer : public IFX_ScanlineComposer, public CFX_Object -{ -public: - - CFX_BitmapStorer(); - - ~CFX_BitmapStorer(); - - virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha); - - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); - - CFX_DIBitmap* GetBitmap() - { - return m_pBitmap; - } - - CFX_DIBitmap* Detach(); - - void Replace(CFX_DIBitmap* pBitmap); -private: - CFX_DIBitmap* m_pBitmap; -}; -class CStretchEngine; -class CFX_ImageStretcher : public CFX_Object -{ -public: - - CFX_ImageStretcher(); - - ~CFX_ImageStretcher(); - - FX_INT32 Start(IFX_ScanlineComposer* pDest, const CFX_DIBSource* pBitmap, - int dest_width, int dest_height, const FX_RECT& bitmap_rect, FX_DWORD flags); - - - FX_INT32 Continue(IFX_Pause* pPause); - IFX_ScanlineComposer* m_pDest; - const CFX_DIBSource* m_pSource; - CStretchEngine* m_pStretchEngine; - FX_DWORD m_Flags; - FX_BOOL m_bFlipX, - m_bFlipY; - int m_DestWidth, - m_DestHeight; - FX_RECT m_ClipRect; - int m_LineIndex; - int m_DestBPP; - FX_LPBYTE m_pScanline; - FX_LPBYTE m_pMaskScanline; - FXDIB_Format m_DestFormat; - FX_INT32 m_Status; - - FX_INT32 StartQuickStretch(); - - FX_INT32 StartStretch(); - - FX_INT32 ContinueQuickStretch(IFX_Pause* pPause); - - FX_INT32 ContinueStretch(IFX_Pause* pPause); -}; -class CFX_ImageTransformer : public CFX_Object -{ -public: - - CFX_ImageTransformer(); - - ~CFX_ImageTransformer(); - - FX_INT32 Start(const CFX_DIBSource* pSrc, const CFX_AffineMatrix* pMatrix, int flags, const FX_RECT* pClip); - - - FX_INT32 Continue(IFX_Pause* pPause); - CFX_AffineMatrix* m_pMatrix; - FX_RECT m_StretchClip; - int m_ResultLeft, m_ResultTop, m_ResultWidth, m_ResultHeight; - CFX_AffineMatrix m_dest2stretch; - CFX_ImageStretcher m_Stretcher; - CFX_BitmapStorer m_Storer; - FX_DWORD m_Flags; - int m_Status; -}; -class CFX_ImageRenderer : public CFX_Object -{ -public: - - CFX_ImageRenderer(); - - ~CFX_ImageRenderer(); - - FX_INT32 Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_DIBSource* pSource, int bitmap_alpha, - FX_DWORD mask_color, const CFX_AffineMatrix* pMatrix, FX_DWORD dib_flags, - FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL); - - FX_INT32 Continue(IFX_Pause* pPause); -protected: - CFX_DIBitmap* m_pDevice; - const CFX_ClipRgn* m_pClipRgn; - int m_BitmapAlpha; - FX_DWORD m_MaskColor; - CFX_AffineMatrix m_Matrix; - CFX_ImageTransformer* m_pTransformer; - CFX_ImageStretcher m_Stretcher; - CFX_BitmapComposer m_Composer; - int m_Status; - int m_DestLeft, m_DestTop; - FX_RECT m_ClipBox; - FX_DWORD m_Flags; - int m_AlphaFlag; - void* m_pIccTransform; - FX_BOOL m_bRgbByteOrder; - int m_BlendType; -}; -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FPDF_DIB_H_ +#define _FPDF_DIB_H_ +#ifndef _FXCRT_EXTENSION_ +#include "../fxcrt/fx_ext.h" +#endif +enum FXDIB_Format { + FXDIB_Invalid = 0, + FXDIB_1bppMask = 0x101, + FXDIB_1bppRgb = 0x001, + FXDIB_1bppCmyk = 0x401, + FXDIB_8bppMask = 0x108, + FXDIB_8bppRgb = 0x008, + FXDIB_8bppRgba = 0x208, + FXDIB_8bppCmyk = 0x408, + FXDIB_8bppCmyka = 0x608, + FXDIB_Rgb = 0x018, + FXDIB_Rgba = 0x218, + FXDIB_Rgb32 = 0x020, + FXDIB_Argb = 0x220, + FXDIB_Cmyk = 0x420, + FXDIB_Cmyka = 0x620, +}; +enum FXDIB_Channel { + FXDIB_Red = 1, + FXDIB_Green, + FXDIB_Blue, + FXDIB_Cyan, + FXDIB_Magenta, + FXDIB_Yellow, + FXDIB_Black, + FXDIB_Alpha +}; +#define FXDIB_DOWNSAMPLE 0x04 +#define FXDIB_INTERPOL 0x20 +#define FXDIB_BICUBIC_INTERPOL 0x80 +#define FXDIB_NOSMOOTH 0x100 +#define FXDIB_PALETTE_LOC 0x01 +#define FXDIB_PALETTE_WIN 0x02 +#define FXDIB_PALETTE_MAC 0x04 +#define FXDIB_BLEND_NORMAL 0 +#define FXDIB_BLEND_MULTIPLY 1 +#define FXDIB_BLEND_SCREEN 2 +#define FXDIB_BLEND_OVERLAY 3 +#define FXDIB_BLEND_DARKEN 4 +#define FXDIB_BLEND_LIGHTEN 5 + +#define FXDIB_BLEND_COLORDODGE 6 +#define FXDIB_BLEND_COLORBURN 7 +#define FXDIB_BLEND_HARDLIGHT 8 +#define FXDIB_BLEND_SOFTLIGHT 9 +#define FXDIB_BLEND_DIFFERENCE 10 +#define FXDIB_BLEND_EXCLUSION 11 +#define FXDIB_BLEND_NONSEPARABLE 21 +#define FXDIB_BLEND_HUE 21 +#define FXDIB_BLEND_SATURATION 22 +#define FXDIB_BLEND_COLOR 23 +#define FXDIB_BLEND_LUMINOSITY 24 +#define FXDIB_BLEND_UNSUPPORTED -1 +typedef FX_DWORD FX_ARGB; +typedef FX_DWORD FX_COLORREF; +typedef FX_DWORD FX_CMYK; +class CFX_ClipRgn; +class CFX_DIBSource; +class CFX_DIBitmap; +#define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) +#define FXSYS_GetRValue(rgb) ((rgb) & 0xff) +#define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff) +#define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff) +#define FX_CCOLOR(val) (255-(val)) +#define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k)) +#define FXSYS_GetCValue(cmyk) ((FX_BYTE)((cmyk) >> 24) & 0xff) +#define FXSYS_GetMValue(cmyk) ((FX_BYTE)((cmyk) >> 16) & 0xff) +#define FXSYS_GetYValue(cmyk) ((FX_BYTE)((cmyk) >> 8) & 0xff) +#define FXSYS_GetKValue(cmyk) ((FX_BYTE)(cmyk) & 0xff) +void CmykDecode(FX_CMYK cmyk, int& c, int& m, int& y, int& k); +inline FX_CMYK CmykEncode(int c, int m, int y, int k) +{ + return (c << 24) | (m << 16) | (y << 8) | k; +} +void ArgbDecode(FX_ARGB argb, int& a, int& r, int&g, int& b); +void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb); +inline FX_ARGB ArgbEncode(int a, int r, int g, int b) +{ + return (a << 24) | (r << 16) | (g << 8) | b; +} +FX_ARGB ArgbEncode(int a, FX_COLORREF rgb); +#define FXARGB_A(argb) ((FX_BYTE)((argb) >> 24)) +#define FXARGB_R(argb) ((FX_BYTE)((argb) >> 16)) +#define FXARGB_G(argb) ((FX_BYTE)((argb) >> 8)) +#define FXARGB_B(argb) ((FX_BYTE)(argb)) +#define FXARGB_MAKE(a,r,g,b) (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) +#define FXARGB_MUL_ALPHA(argb, alpha) (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb) & 0xffffff)) +#define FXRGB2GRAY(r,g,b) (((b) * 11 + (g) * 59 + (r) * 30) / 100) +#define FXCMYK2GRAY(c,m,y,k) (((255-(c)) * (255-(k)) * 30 + (255-(m)) * (255-(k)) * 59 + (255-(y)) * (255-(k)) * 11) / 25500) +#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) (((backdrop) * (255-(source_alpha)) + (source)*(source_alpha))/255) +#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest)*(src)/255) +#define FXCMYK_GETDIB(p) ((((FX_LPBYTE)(p))[0] << 24 | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | ((FX_LPBYTE)(p))[3])) +#define FXCMYK_SETDIB(p, cmyk) ((FX_LPBYTE)(p))[0] = (FX_BYTE)((cmyk) >> 24), \ + ((FX_LPBYTE)(p))[1] = (FX_BYTE)((cmyk) >> 16), \ + ((FX_LPBYTE)(p))[2] = (FX_BYTE)((cmyk) >> 8), \ + ((FX_LPBYTE)(p))[3] = (FX_BYTE)(cmyk)) +#define FXARGB_GETDIB(p) (((FX_LPBYTE)(p))[0]) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[3] << 24) +#define FXARGB_SETDIB(p, argb) ((FX_LPBYTE)(p))[0] = (FX_BYTE)(argb), \ + ((FX_LPBYTE)(p))[1] = (FX_BYTE)((argb) >> 8), \ + ((FX_LPBYTE)(p))[2] = (FX_BYTE)((argb) >> 16), \ + ((FX_LPBYTE)(p))[3] = (FX_BYTE)((argb) >> 24) +#define FXARGB_COPY(dest, src) *(FX_LPBYTE)(dest) = *(FX_LPBYTE)(src), \ + *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ + *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)+2), \ + *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3) +#define FXCMYK_COPY(dest, src) *(FX_LPBYTE)(dest) = *(FX_LPBYTE)(src), \ + *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ + *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)+2), \ + *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3) +#define FXARGB_SETRGBORDERDIB(p, argb) ((FX_LPBYTE)(p))[3] = (FX_BYTE)(argb>>24), \ + ((FX_LPBYTE)(p))[0] = (FX_BYTE)((argb) >> 16), \ + ((FX_LPBYTE)(p))[1] = (FX_BYTE)((argb) >> 8), \ + ((FX_LPBYTE)(p))[2] = (FX_BYTE)(argb) +#define FXARGB_GETRGBORDERDIB(p) (((FX_LPBYTE)(p))[2]) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0] << 16) | (((FX_LPBYTE)(p))[3] << 24) +#define FXARGB_RGBORDERCOPY(dest, src) *((FX_LPBYTE)(dest)+3) = *((FX_LPBYTE)(src)+3), \ + *(FX_LPBYTE)(dest) = *((FX_LPBYTE)(src)+2), \ + *((FX_LPBYTE)(dest)+1) = *((FX_LPBYTE)(src)+1), \ + *((FX_LPBYTE)(dest)+2) = *((FX_LPBYTE)(src)) +#define FXARGB_TODIB(argb) (argb) +#define FXCMYK_TODIB(cmyk) ((FX_BYTE)((cmyk) >> 24) | ((FX_BYTE)((cmyk) >> 16)) << 8 | ((FX_BYTE)((cmyk) >> 8)) << 16 | ((FX_BYTE)(cmyk) << 24)) +#define FXARGB_TOBGRORDERDIB(argb) ((FX_BYTE)(argb>>16) | ((FX_BYTE)(argb>>8)) << 8 | ((FX_BYTE)(argb)) << 16 | ((FX_BYTE)(argb>>24) << 24)) +#define FXGETFLAG_COLORTYPE(flag) (FX_BYTE)((flag)>>8) +#define FXGETFLAG_ALPHA_FILL(flag) (FX_BYTE)(flag) +#define FXGETFLAG_ALPHA_STROKE(flag) (FX_BYTE)((flag)>>16) +#define FXSETFLAG_COLORTYPE(flag, val) flag = (((val)<<8)|(flag&0xffff00ff)) +#define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val)|(flag&0xffffff00)) +#define FXSETFLAG_ALPHA_STROKE(flag, val) flag = (((val)<<16)|(flag&0xff00ffff)) +class CFX_DIBSource : public CFX_Object +{ +public: + + virtual ~CFX_DIBSource(); + + + + int GetWidth() const + { + return m_Width; + } + + int GetHeight() const + { + return m_Height; + } + + FXDIB_Format GetFormat() const + { + return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); + } + + FX_DWORD GetPitch() const + { + return m_Pitch; + } + + FX_DWORD* GetPalette() const + { + return m_pPalette; + } + + + + virtual FX_LPBYTE GetBuffer() const + { + return NULL; + } + + virtual FX_LPCBYTE GetScanline(int line) const = 0; + + virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const + { + return FALSE; + } + + virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, + int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const = 0; + + virtual void SetDownSampleSize(int width, int height) const {} + + int GetBPP() const + { + return m_bpp; + } + + FX_BOOL IsAlphaMask() const + { + return m_AlphaFlag == 1; + } + + FX_BOOL HasAlpha() const + { + return m_AlphaFlag & 2 ? TRUE : FALSE; + } + + FX_BOOL IsOpaqueImage() const + { + return !(m_AlphaFlag & 3); + } + + FX_BOOL IsCmykImage() const + { + return m_AlphaFlag & 4 ? TRUE : FALSE; + } + + + + int GetPaletteSize() const + { + return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); + } + + FX_DWORD GetPaletteEntry(int index) const; + + void SetPaletteEntry(int index, FX_DWORD color); + FX_DWORD GetPaletteArgb(int index) const + { + return GetPaletteEntry(index); + } + void SetPaletteArgb(int index, FX_DWORD color) + { + SetPaletteEntry(index, color); + } + + void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); + + + CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; + + CFX_DIBitmap* CloneConvert(FXDIB_Format format, const FX_RECT* pClip = NULL, void* pIccTransform = NULL) const; + + CFX_DIBitmap* StretchTo(int dest_width, int dest_height, FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; + + + CFX_DIBitmap* TransformTo(const CFX_AffineMatrix* pMatrix, int& left, int &top, + FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; + + CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; + + FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip = NULL); + + CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_RECT* pClip = NULL) const; + + CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; + + void GetOverlapRect(int& dest_left, int& dest_top, int& width, int& height, int src_width, + int src_height, int& src_left, int& src_top, const CFX_ClipRgn* pClipRgn); + + CFX_DIBitmap* m_pAlphaMask; +protected: + + CFX_DIBSource(); + + int m_Width; + + int m_Height; + + int m_bpp; + + FX_DWORD m_AlphaFlag; + + FX_DWORD m_Pitch; + + FX_DWORD* m_pPalette; + + void BuildPalette(); + + FX_BOOL BuildAlphaMask(); + + int FindPalette(FX_DWORD color) const; + + void GetPalette(FX_DWORD* pal, int alpha) const; +}; +class CFX_DIBitmap : public CFX_DIBSource +{ +public: + + virtual ~CFX_DIBitmap(); + + CFX_DIBitmap(); + + CFX_DIBitmap(const CFX_DIBitmap& src); + + FX_BOOL Create(int width, int height, FXDIB_Format format, FX_LPBYTE pBuffer = NULL, int pitch = 0); + + FX_BOOL Copy(const CFX_DIBSource* pSrc); + + virtual FX_LPBYTE GetBuffer() const + { + return m_pBuffer; + } + + virtual FX_LPCBYTE GetScanline(int line) const + { + return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL; + } + + virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, + int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; + + void TakeOver(CFX_DIBitmap* pSrcBitmap); + + FX_BOOL ConvertFormat(FXDIB_Format format, void* pIccTransform = NULL); + + void Clear(FX_DWORD color); + + FX_DWORD GetPixel(int x, int y) const; + + void SetPixel(int x, int y, FX_DWORD color); + + FX_BOOL LoadChannel(FXDIB_Channel destChannel, const CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel); + + FX_BOOL LoadChannel(FXDIB_Channel destChannel, int value); + + FX_BOOL MultiplyAlpha(int alpha); + + FX_BOOL MultiplyAlpha(const CFX_DIBSource* pAlphaMask); + + FX_BOOL TransferBitmap(int dest_left, int dest_top, int width, int height, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform = NULL); + + FX_BOOL CompositeBitmap(int dest_left, int dest_top, int width, int height, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, + int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, void* pIccTransform = NULL); + + FX_BOOL TransferMask(int dest_left, int dest_top, int width, int height, + const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL CompositeMask(int dest_left, int dest_top, int width, int height, + const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, + int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL CompositeRect(int dest_left, int dest_top, int width, int height, FX_DWORD color, int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor); + + FX_BOOL DitherFS(const FX_DWORD* pPalette, int pal_size, const FX_RECT* pRect = NULL); +protected: + + FX_LPBYTE m_pBuffer; + + FX_BOOL m_bExtBuf; + + FX_BOOL GetGrayData(void* pIccTransform = NULL); +}; +class CFX_DIBExtractor : public CFX_Object +{ +public: + + CFX_DIBExtractor(const CFX_DIBSource* pSrc); + + ~CFX_DIBExtractor(); + + operator CFX_DIBitmap*() + { + return m_pBitmap; + } +private: + + CFX_DIBitmap* m_pBitmap; +}; +typedef CFX_CountRef CFX_DIBitmapRef; +class CFX_FilteredDIB : public CFX_DIBSource +{ +public: + + CFX_FilteredDIB(); + + ~CFX_FilteredDIB(); + + void LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc = FALSE); + + virtual FXDIB_Format GetDestFormat() = 0; + + virtual FX_DWORD* GetDestPalette() = 0; + + + virtual void TranslateScanline(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf) const = 0; + + virtual void TranslateDownSamples(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf, int pixels, int Bpp) const = 0; +protected: + virtual FX_LPCBYTE GetScanline(int line) const; + virtual void DownSampleScanline(int line, FX_LPBYTE dest_scan, int dest_bpp, + int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; + + const CFX_DIBSource* m_pSrc; + + FX_BOOL m_bAutoDropSrc; + + FX_LPBYTE m_pScanline; +}; +class IFX_ScanlineComposer +{ +public: + + virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha = NULL) = 0; + + + virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette) = 0; +}; +class CFX_ScanlineCompositor : public CFX_Object +{ +public: + + CFX_ScanlineCompositor(); + + ~CFX_ScanlineCompositor(); + + FX_BOOL Init(FXDIB_Format dest_format, FXDIB_Format src_format, FX_INT32 width, FX_DWORD* pSrcPalette, + FX_DWORD mask_color, int blend_type, FX_BOOL bClip, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); + + + void CompositeRgbBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan, + FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); + + + void CompositePalBitmapLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan, + FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); + + + void CompositeByteMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int width, FX_LPCBYTE clip_scan, + FX_LPBYTE dst_extra_alpha = NULL); + + + void CompositeBitMaskLine(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int src_left, int width, FX_LPCBYTE clip_scan, + FX_LPBYTE dst_extra_alpha = NULL); +protected: + int m_Transparency; + FXDIB_Format m_SrcFormat, + m_DestFormat; + FX_DWORD* m_pSrcPalette; + + int m_MaskAlpha, + m_MaskRed, + m_MaskGreen, + m_MaskBlue, + m_MaskBlack; + int m_BlendType; + void* m_pIccTransform; + FX_LPBYTE m_pCacheScanline; + int m_CacheSize; + FX_BOOL m_bRgbByteOrder; +}; +class CFX_BitmapComposer : public IFX_ScanlineComposer, public CFX_Object +{ +public: + + CFX_BitmapComposer(); + + ~CFX_BitmapComposer(); + + + void Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha, + FX_DWORD mask_color, FX_RECT& dest_rect, FX_BOOL bVertical, + FX_BOOL bFlipX, FX_BOOL bFlipY, FX_BOOL bRgbByteOrder = FALSE, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + + virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); + + + virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha); +protected: + + void DoCompose(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int dest_width, FX_LPCBYTE clip_scan, + FX_LPCBYTE src_extra_alpha = NULL, FX_LPBYTE dst_extra_alpha = NULL); + CFX_DIBitmap* m_pBitmap; + const CFX_ClipRgn* m_pClipRgn; + FXDIB_Format m_SrcFormat; + int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha; + FX_DWORD m_MaskColor; + const CFX_DIBitmap* m_pClipMask; + CFX_ScanlineCompositor m_Compositor; + FX_BOOL m_bVertical, m_bFlipX, m_bFlipY; + int m_AlphaFlag; + void* m_pIccTransform; + FX_BOOL m_bRgbByteOrder; + int m_BlendType; + void ComposeScanlineV(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha = NULL); + FX_LPBYTE m_pScanlineV, m_pClipScanV, m_pAddClipScan, m_pScanlineAlphaV; +}; +class CFX_BitmapStorer : public IFX_ScanlineComposer, public CFX_Object +{ +public: + + CFX_BitmapStorer(); + + ~CFX_BitmapStorer(); + + virtual void ComposeScanline(int line, FX_LPCBYTE scanline, FX_LPCBYTE scan_extra_alpha); + + virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); + + CFX_DIBitmap* GetBitmap() + { + return m_pBitmap; + } + + CFX_DIBitmap* Detach(); + + void Replace(CFX_DIBitmap* pBitmap); +private: + CFX_DIBitmap* m_pBitmap; +}; +class CStretchEngine; +class CFX_ImageStretcher : public CFX_Object +{ +public: + + CFX_ImageStretcher(); + + ~CFX_ImageStretcher(); + + FX_INT32 Start(IFX_ScanlineComposer* pDest, const CFX_DIBSource* pBitmap, + int dest_width, int dest_height, const FX_RECT& bitmap_rect, FX_DWORD flags); + + + FX_INT32 Continue(IFX_Pause* pPause); + IFX_ScanlineComposer* m_pDest; + const CFX_DIBSource* m_pSource; + CStretchEngine* m_pStretchEngine; + FX_DWORD m_Flags; + FX_BOOL m_bFlipX, + m_bFlipY; + int m_DestWidth, + m_DestHeight; + FX_RECT m_ClipRect; + int m_LineIndex; + int m_DestBPP; + FX_LPBYTE m_pScanline; + FX_LPBYTE m_pMaskScanline; + FXDIB_Format m_DestFormat; + FX_INT32 m_Status; + + FX_INT32 StartQuickStretch(); + + FX_INT32 StartStretch(); + + FX_INT32 ContinueQuickStretch(IFX_Pause* pPause); + + FX_INT32 ContinueStretch(IFX_Pause* pPause); +}; +class CFX_ImageTransformer : public CFX_Object +{ +public: + + CFX_ImageTransformer(); + + ~CFX_ImageTransformer(); + + FX_INT32 Start(const CFX_DIBSource* pSrc, const CFX_AffineMatrix* pMatrix, int flags, const FX_RECT* pClip); + + + FX_INT32 Continue(IFX_Pause* pPause); + CFX_AffineMatrix* m_pMatrix; + FX_RECT m_StretchClip; + int m_ResultLeft, m_ResultTop, m_ResultWidth, m_ResultHeight; + CFX_AffineMatrix m_dest2stretch; + CFX_ImageStretcher m_Stretcher; + CFX_BitmapStorer m_Storer; + FX_DWORD m_Flags; + int m_Status; +}; +class CFX_ImageRenderer : public CFX_Object +{ +public: + + CFX_ImageRenderer(); + + ~CFX_ImageRenderer(); + + FX_INT32 Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, + const CFX_DIBSource* pSource, int bitmap_alpha, + FX_DWORD mask_color, const CFX_AffineMatrix* pMatrix, FX_DWORD dib_flags, + FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_INT32 Continue(IFX_Pause* pPause); +protected: + CFX_DIBitmap* m_pDevice; + const CFX_ClipRgn* m_pClipRgn; + int m_BitmapAlpha; + FX_DWORD m_MaskColor; + CFX_AffineMatrix m_Matrix; + CFX_ImageTransformer* m_pTransformer; + CFX_ImageStretcher m_Stretcher; + CFX_BitmapComposer m_Composer; + int m_Status; + int m_DestLeft, m_DestTop; + FX_RECT m_ClipBox; + FX_DWORD m_Flags; + int m_AlphaFlag; + void* m_pIccTransform; + FX_BOOL m_bRgbByteOrder; + int m_BlendType; +}; +#endif diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h index abfa9b8b5d..dc96debeb6 100644 --- a/core/include/fxge/fx_font.h +++ b/core/include/fxge/fx_font.h @@ -1,428 +1,428 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _FX_FONT_H_ -#define _FX_FONT_H_ -#ifndef _FXCRT_EXTENSION_ -#include "../../include/fxcrt/fx_ext.h" -#endif -#ifndef _FX_DIB_H_ -#include "fx_dib.h" -#endif -typedef struct FT_FaceRec_* FXFT_Face; -typedef void* FXFT_Library; -class IFX_FontEncoding; -class CFX_PathData; -class CFX_SubstFont; -class CFX_FaceCache; -class IFX_FontMapper; -class CFX_FontMapper; -class IFX_SystemFontInfo; -class CFontFileFaceInfo; -#define FXFONT_FIXED_PITCH 0x01 -#define FXFONT_SERIF 0x02 -#define FXFONT_SYMBOLIC 0x04 -#define FXFONT_SCRIPT 0x08 -#define FXFONT_ITALIC 0x40 -#define FXFONT_BOLD 0x40000 -#define FXFONT_USEEXTERNATTR 0x80000 -#define FXFONT_CIDFONT 0x100000 -#define FXFONT_ANSI_CHARSET 0 -#define FXFONT_DEFAULT_CHARSET 1 -#define FXFONT_SYMBOL_CHARSET 2 -#define FXFONT_SHIFTJIS_CHARSET 128 -#define FXFONT_HANGEUL_CHARSET 129 -#define FXFONT_GB2312_CHARSET 134 -#define FXFONT_CHINESEBIG5_CHARSET 136 -#define FXFONT_THAI_CHARSET 222 -#define FXFONT_EASTEUROPE_CHARSET 238 -#define FXFONT_RUSSIAN_CHARSET 204 -#define FXFONT_GREEK_CHARSET 161 -#define FXFONT_TURKISH_CHARSET 162 -#define FXFONT_HEBREW_CHARSET 177 -#define FXFONT_ARABIC_CHARSET 178 -#define FXFONT_BALTIC_CHARSET 186 -#define FXFONT_FF_FIXEDPITCH 1 -#define FXFONT_FF_ROMAN (1<<4) -#define FXFONT_FF_SCRIPT (4<<4) -#define FXFONT_FW_NORMAL 400 -#define FXFONT_FW_BOLD 700 -class CFX_Font : public CFX_Object -{ -public: - CFX_Font(); - ~CFX_Font(); - - FX_BOOL LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, FX_BOOL bVertical = FALSE); - - FX_BOOL LoadEmbedded(FX_LPCBYTE data, FX_DWORD size); - - FX_BOOL LoadFile(IFX_FileRead* pFile); - - FXFT_Face GetFace() const - { - return m_Face; - } - - - const CFX_SubstFont* GetSubstFont() const - { - return m_pSubstFont; - } - - CFX_PathData* LoadGlyphPath(FX_DWORD glyph_index, int dest_width = 0); - - int GetGlyphWidth(FX_DWORD glyph_index); - - int GetAscent() const; - - int GetDescent() const; - - FX_BOOL GetGlyphBBox(FX_DWORD glyph_index, FX_RECT &bbox); - - FX_BOOL IsItalic(); - - FX_BOOL IsBold(); - - FX_BOOL IsFixedWidth(); - - FX_BOOL IsVertical() const - { - return m_bVertical; - } - - CFX_WideString GetPsName() const; - - - CFX_ByteString GetFamilyName() const; - - CFX_ByteString GetFaceName() const; - - - FX_BOOL IsTTFont(); - - FX_BOOL GetBBox(FX_RECT &bbox); - - int GetHeight(); - - int GetULPos(); - - int GetULthickness(); - - int GetMaxAdvanceWidth(); - - FXFT_Face m_Face; - - CFX_SubstFont* m_pSubstFont; - FX_BOOL IsEmbedded() - { - return m_bEmbedded; - } - - void AdjustMMParams(int glyph_index, int width, int weight); - FX_LPBYTE m_pFontDataAllocation; - FX_LPBYTE m_pFontData; - FX_LPBYTE m_pGsubData; - FX_DWORD m_dwSize; - CFX_BinaryBuf m_OtfFontData; - void* m_hHandle; - void* m_pPlatformFont; - void* m_pPlatformFontCollection; - void* m_pDwFont; - FX_BOOL m_bDwLoaded; - void ReleasePlatformResource(); - - void DeleteFace(); -protected: - - FX_BOOL m_bEmbedded; - FX_BOOL m_bVertical; - void* m_pOwnedStream; -}; -#define ENCODING_INTERNAL 0 -#define ENCODING_UNICODE 1 -class IFX_FontEncoding : public CFX_Object -{ -public: - virtual ~IFX_FontEncoding() {} - - virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0; - - virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0; - - virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; -}; -IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont); -#define FXFONT_SUBST_MM 0x01 -#define FXFONT_SUBST_GLYPHPATH 0x04 -#define FXFONT_SUBST_CLEARTYPE 0x08 -#define FXFONT_SUBST_TRANSFORM 0x10 -#define FXFONT_SUBST_NONSYMBOL 0x20 -#define FXFONT_SUBST_EXACT 0x40 -#define FXFONT_SUBST_STANDARD 0x80 -class CFX_SubstFont : public CFX_Object -{ -public: - - CFX_SubstFont(); - - FX_LPVOID m_ExtHandle; - - CFX_ByteString m_Family; - - int m_Charset; - - FX_DWORD m_SubstFlags; - - int m_Weight; - - int m_ItalicAngle; - - FX_BOOL m_bSubstOfCJK; - - int m_WeightCJK; - - FX_BOOL m_bItlicCJK; -}; -#define FX_FONT_FLAG_SERIF 0x01 -#define FX_FONT_FLAG_FIXEDPITCH 0x02 -#define FX_FONT_FLAG_ITALIC 0x04 -#define FX_FONT_FLAG_BOLD 0x08 -#define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 -#define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 -#define FX_FONT_FLAG_MULTIPLEMASTER 0x40 -typedef struct { - FX_LPCBYTE m_pFontData; - FX_DWORD m_dwSize; -} FoxitFonts; -class CFX_FontMgr : public CFX_Object -{ -public: - CFX_FontMgr(); - ~CFX_FontMgr(); - void InitFTLibrary(); - FXFT_Face GetCachedFace(const CFX_ByteString& face_name, - int weight, FX_BOOL bItalic, FX_LPBYTE& pFontData); - FXFT_Face AddCachedFace(const CFX_ByteString& face_name, - int weight, FX_BOOL bItalic, FX_LPBYTE pData, FX_DWORD size, int face_index); - FXFT_Face GetCachedTTCFace(int ttc_size, FX_DWORD checksum, - int font_offset, FX_LPBYTE& pFontData); - FXFT_Face AddCachedTTCFace(int ttc_size, FX_DWORD checksum, - FX_LPBYTE pData, FX_DWORD size, int font_offset); - FXFT_Face GetFileFace(FX_LPCSTR filename, int face_index); - FXFT_Face GetFixedFace(FX_LPCBYTE pData, FX_DWORD size, int face_index); - void ReleaseFace(FXFT_Face face); - void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); - FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); - - void FreeCache(); - - FX_BOOL GetStandardFont(FX_LPCBYTE& pFontData, FX_DWORD& size, int index); - CFX_FontMapper* m_pBuiltinMapper; - IFX_FontMapper* m_pExtMapper; - CFX_MapByteStringToPtr m_FaceMap; - FXFT_Library m_FTLibrary; - FoxitFonts m_ExternalFonts[16]; -}; -class IFX_FontMapper : public CFX_Object -{ -public: - - virtual ~IFX_FontMapper() {} - - virtual FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont) = 0; - - CFX_FontMgr* m_pFontMgr; -}; -class IFX_FontEnumerator -{ -public: - - virtual void HitFont() = 0; - - virtual void Finish() = 0; -}; -class IFX_AdditionalFontEnum -{ -public: - virtual int CountFiles() = 0; - virtual IFX_FileStream* GetFontFile(int index) = 0; -}; -class CFX_FontMapper : public IFX_FontMapper -{ -public: - CFX_FontMapper(); - virtual ~CFX_FontMapper(); - void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); - IFX_SystemFontInfo* GetSystemFontInfo() - { - return m_pFontInfo; - } - void AddInstalledFont(const CFX_ByteString& name, int charset); - void LoadInstalledFonts(); - CFX_ByteStringArray m_InstalledTTFonts; - void SetFontEnumerator(IFX_FontEnumerator* pFontEnumerator) - { - m_pFontEnumerator = pFontEnumerator; - } - IFX_FontEnumerator* GetFontEnumerator() const - { - return m_pFontEnumerator; - } - virtual FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); -private: - CFX_ByteString GetPSNameFromTT(void* hFont); - CFX_ByteString MatchInstalledFonts(const CFX_ByteString& norm_name); - FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseFont, int italic_angle, int weight, int picthfamily); - - FX_BOOL m_bListLoaded; - FXFT_Face m_MMFaces[2]; - CFX_ByteString m_LastFamily; - CFX_DWordArray m_CharsetArray; - CFX_ByteStringArray m_FaceArray; - IFX_SystemFontInfo* m_pFontInfo; - FXFT_Face m_FoxitFaces[14]; - IFX_FontEnumerator* m_pFontEnumerator; -}; -class IFX_SystemFontInfo : public CFX_Object -{ -public: - static IFX_SystemFontInfo* CreateDefault(); - virtual void Release() = 0; - virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) = 0; - virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR face, FX_BOOL& bExact) = 0; - virtual void* GetFont(FX_LPCSTR face) = 0; - virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) = 0; - virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) = 0; - virtual FX_BOOL GetFontCharset(void* hFont, int& charset) = 0; - virtual int GetFaceIndex(void* hFont) - { - return 0; - } - virtual void DeleteFont(void* hFont) = 0; - virtual void* RetainFont(void* hFont) - { - return NULL; - } -}; -class CFX_FolderFontInfo : public IFX_SystemFontInfo -{ -public: - CFX_FolderFontInfo(); - ~CFX_FolderFontInfo(); - void AddPath(FX_BSTR path); - virtual void Release(); - virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper); - virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR face, FX_BOOL& bExact); - virtual void* GetFont(FX_LPCSTR face); - virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size); - virtual void DeleteFont(void* hFont); - virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name); - virtual FX_BOOL GetFontCharset(void* hFont, int& charset); -protected: - CFX_MapByteStringToPtr m_FontList; - CFX_ByteStringArray m_PathList; - CFX_FontMapper* m_pMapper; - void ScanPath(CFX_ByteString& path); - void ScanFile(CFX_ByteString& path); - void ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_DWORD filesize, FX_DWORD offset); -}; -class CFX_CountedFaceCache : public CFX_Object -{ -public: - CFX_FaceCache* m_Obj; - FX_DWORD m_nCount; -}; -typedef CFX_MapPtrTemplate CFX_FTCacheMap; -class CFX_FontCache : public CFX_Object -{ -public: - ~CFX_FontCache(); - CFX_FaceCache* GetCachedFace(CFX_Font* pFont); - void ReleaseCachedFace(CFX_Font* pFont); - void FreeCache(FX_BOOL bRelease = FALSE); - -private: - CFX_FTCacheMap m_FTFaceMap; - CFX_FTCacheMap m_ExtFaceMap; -}; -class CFX_AutoFontCache -{ -public: - CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) - : m_pFontCache(pFontCache) - , m_pFont(pFont) - { - } - ~CFX_AutoFontCache() - { - m_pFontCache->ReleaseCachedFace(m_pFont); - } - CFX_FontCache* m_pFontCache; - CFX_Font* m_pFont; -}; -#define FX_FONTCACHE_DEFINE(pFontCache, pFont) CFX_AutoFontCache autoFontCache((pFontCache), (pFont)) -class CFX_GlyphBitmap : public CFX_Object -{ -public: - int m_Top; - int m_Left; - CFX_DIBitmap m_Bitmap; -}; -class CFX_FaceCache : public CFX_Object -{ -public: - ~CFX_FaceCache(); - const CFX_GlyphBitmap* LoadGlyphBitmap(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, const CFX_AffineMatrix* pMatrix, - int dest_width, int anti_alias, int& text_flags); - const CFX_PathData* LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width); - - - CFX_FaceCache(FXFT_Face face); -private: - FXFT_Face m_Face; - CFX_GlyphBitmap* RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, - const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); - CFX_GlyphBitmap* RenderGlyph_Nativetext(CFX_Font* pFont, FX_DWORD glyph_index, - const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); - CFX_GlyphBitmap* LookUpGlyphBitmap(CFX_Font* pFont, const CFX_AffineMatrix* pMatrix, CFX_ByteStringC& FaceGlyphsKey, - FX_DWORD glyph_index, FX_BOOL bFontStyle, int dest_width, int anti_alias); - CFX_MapByteStringToPtr m_SizeMap; - CFX_MapPtrToPtr m_PathMap; - CFX_DIBitmap* m_pBitmap; - void* m_pPlatformGraphics; - void* m_pPlatformBitmap; - void* m_hDC; - void* m_hBitmap; - void* m_hOldBitmap; - void* m_hGdiFont; - void* m_hOldGdiFont; - - void InitPlatform(); - void DestroyPlatform(); -}; -typedef struct { - const CFX_GlyphBitmap* m_pGlyph; - int m_OriginX, m_OriginY; - FX_FLOAT m_fOriginX, m_fOriginY; -} FXTEXT_GLYPHPOS; -FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars, int anti_alias, FX_FLOAT retinaScaleX = 1.0f, FX_FLOAT retinaScaleY = 1.0f); -FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size, - CFX_AffineMatrix* pMatrix, unsigned long glyph_index, unsigned long argb); -FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size, - CFX_AffineMatrix* pText_matrix, unsigned short const* text, unsigned long argb); -class IFX_GSUBTable -{ -public: - virtual void Release() = 0; - virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) = 0; -}; -IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont); -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FX_FONT_H_ +#define _FX_FONT_H_ +#ifndef _FXCRT_EXTENSION_ +#include "../../include/fxcrt/fx_ext.h" +#endif +#ifndef _FX_DIB_H_ +#include "fx_dib.h" +#endif +typedef struct FT_FaceRec_* FXFT_Face; +typedef void* FXFT_Library; +class IFX_FontEncoding; +class CFX_PathData; +class CFX_SubstFont; +class CFX_FaceCache; +class IFX_FontMapper; +class CFX_FontMapper; +class IFX_SystemFontInfo; +class CFontFileFaceInfo; +#define FXFONT_FIXED_PITCH 0x01 +#define FXFONT_SERIF 0x02 +#define FXFONT_SYMBOLIC 0x04 +#define FXFONT_SCRIPT 0x08 +#define FXFONT_ITALIC 0x40 +#define FXFONT_BOLD 0x40000 +#define FXFONT_USEEXTERNATTR 0x80000 +#define FXFONT_CIDFONT 0x100000 +#define FXFONT_ANSI_CHARSET 0 +#define FXFONT_DEFAULT_CHARSET 1 +#define FXFONT_SYMBOL_CHARSET 2 +#define FXFONT_SHIFTJIS_CHARSET 128 +#define FXFONT_HANGEUL_CHARSET 129 +#define FXFONT_GB2312_CHARSET 134 +#define FXFONT_CHINESEBIG5_CHARSET 136 +#define FXFONT_THAI_CHARSET 222 +#define FXFONT_EASTEUROPE_CHARSET 238 +#define FXFONT_RUSSIAN_CHARSET 204 +#define FXFONT_GREEK_CHARSET 161 +#define FXFONT_TURKISH_CHARSET 162 +#define FXFONT_HEBREW_CHARSET 177 +#define FXFONT_ARABIC_CHARSET 178 +#define FXFONT_BALTIC_CHARSET 186 +#define FXFONT_FF_FIXEDPITCH 1 +#define FXFONT_FF_ROMAN (1<<4) +#define FXFONT_FF_SCRIPT (4<<4) +#define FXFONT_FW_NORMAL 400 +#define FXFONT_FW_BOLD 700 +class CFX_Font : public CFX_Object +{ +public: + CFX_Font(); + ~CFX_Font(); + + FX_BOOL LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, + int weight, int italic_angle, int CharsetCP, FX_BOOL bVertical = FALSE); + + FX_BOOL LoadEmbedded(FX_LPCBYTE data, FX_DWORD size); + + FX_BOOL LoadFile(IFX_FileRead* pFile); + + FXFT_Face GetFace() const + { + return m_Face; + } + + + const CFX_SubstFont* GetSubstFont() const + { + return m_pSubstFont; + } + + CFX_PathData* LoadGlyphPath(FX_DWORD glyph_index, int dest_width = 0); + + int GetGlyphWidth(FX_DWORD glyph_index); + + int GetAscent() const; + + int GetDescent() const; + + FX_BOOL GetGlyphBBox(FX_DWORD glyph_index, FX_RECT &bbox); + + FX_BOOL IsItalic(); + + FX_BOOL IsBold(); + + FX_BOOL IsFixedWidth(); + + FX_BOOL IsVertical() const + { + return m_bVertical; + } + + CFX_WideString GetPsName() const; + + + CFX_ByteString GetFamilyName() const; + + CFX_ByteString GetFaceName() const; + + + FX_BOOL IsTTFont(); + + FX_BOOL GetBBox(FX_RECT &bbox); + + int GetHeight(); + + int GetULPos(); + + int GetULthickness(); + + int GetMaxAdvanceWidth(); + + FXFT_Face m_Face; + + CFX_SubstFont* m_pSubstFont; + FX_BOOL IsEmbedded() + { + return m_bEmbedded; + } + + void AdjustMMParams(int glyph_index, int width, int weight); + FX_LPBYTE m_pFontDataAllocation; + FX_LPBYTE m_pFontData; + FX_LPBYTE m_pGsubData; + FX_DWORD m_dwSize; + CFX_BinaryBuf m_OtfFontData; + void* m_hHandle; + void* m_pPlatformFont; + void* m_pPlatformFontCollection; + void* m_pDwFont; + FX_BOOL m_bDwLoaded; + void ReleasePlatformResource(); + + void DeleteFace(); +protected: + + FX_BOOL m_bEmbedded; + FX_BOOL m_bVertical; + void* m_pOwnedStream; +}; +#define ENCODING_INTERNAL 0 +#define ENCODING_UNICODE 1 +class IFX_FontEncoding : public CFX_Object +{ +public: + virtual ~IFX_FontEncoding() {} + + virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0; + + virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0; + + virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; +}; +IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont); +#define FXFONT_SUBST_MM 0x01 +#define FXFONT_SUBST_GLYPHPATH 0x04 +#define FXFONT_SUBST_CLEARTYPE 0x08 +#define FXFONT_SUBST_TRANSFORM 0x10 +#define FXFONT_SUBST_NONSYMBOL 0x20 +#define FXFONT_SUBST_EXACT 0x40 +#define FXFONT_SUBST_STANDARD 0x80 +class CFX_SubstFont : public CFX_Object +{ +public: + + CFX_SubstFont(); + + FX_LPVOID m_ExtHandle; + + CFX_ByteString m_Family; + + int m_Charset; + + FX_DWORD m_SubstFlags; + + int m_Weight; + + int m_ItalicAngle; + + FX_BOOL m_bSubstOfCJK; + + int m_WeightCJK; + + FX_BOOL m_bItlicCJK; +}; +#define FX_FONT_FLAG_SERIF 0x01 +#define FX_FONT_FLAG_FIXEDPITCH 0x02 +#define FX_FONT_FLAG_ITALIC 0x04 +#define FX_FONT_FLAG_BOLD 0x08 +#define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 +#define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 +#define FX_FONT_FLAG_MULTIPLEMASTER 0x40 +typedef struct { + FX_LPCBYTE m_pFontData; + FX_DWORD m_dwSize; +} FoxitFonts; +class CFX_FontMgr : public CFX_Object +{ +public: + CFX_FontMgr(); + ~CFX_FontMgr(); + void InitFTLibrary(); + FXFT_Face GetCachedFace(const CFX_ByteString& face_name, + int weight, FX_BOOL bItalic, FX_LPBYTE& pFontData); + FXFT_Face AddCachedFace(const CFX_ByteString& face_name, + int weight, FX_BOOL bItalic, FX_LPBYTE pData, FX_DWORD size, int face_index); + FXFT_Face GetCachedTTCFace(int ttc_size, FX_DWORD checksum, + int font_offset, FX_LPBYTE& pFontData); + FXFT_Face AddCachedTTCFace(int ttc_size, FX_DWORD checksum, + FX_LPBYTE pData, FX_DWORD size, int font_offset); + FXFT_Face GetFileFace(FX_LPCSTR filename, int face_index); + FXFT_Face GetFixedFace(FX_LPCBYTE pData, FX_DWORD size, int face_index); + void ReleaseFace(FXFT_Face face); + void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); + FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, + int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); + + void FreeCache(); + + FX_BOOL GetStandardFont(FX_LPCBYTE& pFontData, FX_DWORD& size, int index); + CFX_FontMapper* m_pBuiltinMapper; + IFX_FontMapper* m_pExtMapper; + CFX_MapByteStringToPtr m_FaceMap; + FXFT_Library m_FTLibrary; + FoxitFonts m_ExternalFonts[16]; +}; +class IFX_FontMapper : public CFX_Object +{ +public: + + virtual ~IFX_FontMapper() {} + + virtual FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, + int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont) = 0; + + CFX_FontMgr* m_pFontMgr; +}; +class IFX_FontEnumerator +{ +public: + + virtual void HitFont() = 0; + + virtual void Finish() = 0; +}; +class IFX_AdditionalFontEnum +{ +public: + virtual int CountFiles() = 0; + virtual IFX_FileStream* GetFontFile(int index) = 0; +}; +class CFX_FontMapper : public IFX_FontMapper +{ +public: + CFX_FontMapper(); + virtual ~CFX_FontMapper(); + void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); + IFX_SystemFontInfo* GetSystemFontInfo() + { + return m_pFontInfo; + } + void AddInstalledFont(const CFX_ByteString& name, int charset); + void LoadInstalledFonts(); + CFX_ByteStringArray m_InstalledTTFonts; + void SetFontEnumerator(IFX_FontEnumerator* pFontEnumerator) + { + m_pFontEnumerator = pFontEnumerator; + } + IFX_FontEnumerator* GetFontEnumerator() const + { + return m_pFontEnumerator; + } + virtual FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, + int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); +private: + CFX_ByteString GetPSNameFromTT(void* hFont); + CFX_ByteString MatchInstalledFonts(const CFX_ByteString& norm_name); + FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseFont, int italic_angle, int weight, int picthfamily); + + FX_BOOL m_bListLoaded; + FXFT_Face m_MMFaces[2]; + CFX_ByteString m_LastFamily; + CFX_DWordArray m_CharsetArray; + CFX_ByteStringArray m_FaceArray; + IFX_SystemFontInfo* m_pFontInfo; + FXFT_Face m_FoxitFaces[14]; + IFX_FontEnumerator* m_pFontEnumerator; +}; +class IFX_SystemFontInfo : public CFX_Object +{ +public: + static IFX_SystemFontInfo* CreateDefault(); + virtual void Release() = 0; + virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) = 0; + virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR face, FX_BOOL& bExact) = 0; + virtual void* GetFont(FX_LPCSTR face) = 0; + virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) = 0; + virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) = 0; + virtual FX_BOOL GetFontCharset(void* hFont, int& charset) = 0; + virtual int GetFaceIndex(void* hFont) + { + return 0; + } + virtual void DeleteFont(void* hFont) = 0; + virtual void* RetainFont(void* hFont) + { + return NULL; + } +}; +class CFX_FolderFontInfo : public IFX_SystemFontInfo +{ +public: + CFX_FolderFontInfo(); + ~CFX_FolderFontInfo(); + void AddPath(FX_BSTR path); + virtual void Release(); + virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper); + virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR face, FX_BOOL& bExact); + virtual void* GetFont(FX_LPCSTR face); + virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size); + virtual void DeleteFont(void* hFont); + virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name); + virtual FX_BOOL GetFontCharset(void* hFont, int& charset); +protected: + CFX_MapByteStringToPtr m_FontList; + CFX_ByteStringArray m_PathList; + CFX_FontMapper* m_pMapper; + void ScanPath(CFX_ByteString& path); + void ScanFile(CFX_ByteString& path); + void ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_DWORD filesize, FX_DWORD offset); +}; +class CFX_CountedFaceCache : public CFX_Object +{ +public: + CFX_FaceCache* m_Obj; + FX_DWORD m_nCount; +}; +typedef CFX_MapPtrTemplate CFX_FTCacheMap; +class CFX_FontCache : public CFX_Object +{ +public: + ~CFX_FontCache(); + CFX_FaceCache* GetCachedFace(CFX_Font* pFont); + void ReleaseCachedFace(CFX_Font* pFont); + void FreeCache(FX_BOOL bRelease = FALSE); + +private: + CFX_FTCacheMap m_FTFaceMap; + CFX_FTCacheMap m_ExtFaceMap; +}; +class CFX_AutoFontCache +{ +public: + CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) + : m_pFontCache(pFontCache) + , m_pFont(pFont) + { + } + ~CFX_AutoFontCache() + { + m_pFontCache->ReleaseCachedFace(m_pFont); + } + CFX_FontCache* m_pFontCache; + CFX_Font* m_pFont; +}; +#define FX_FONTCACHE_DEFINE(pFontCache, pFont) CFX_AutoFontCache autoFontCache((pFontCache), (pFont)) +class CFX_GlyphBitmap : public CFX_Object +{ +public: + int m_Top; + int m_Left; + CFX_DIBitmap m_Bitmap; +}; +class CFX_FaceCache : public CFX_Object +{ +public: + ~CFX_FaceCache(); + const CFX_GlyphBitmap* LoadGlyphBitmap(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, const CFX_AffineMatrix* pMatrix, + int dest_width, int anti_alias, int& text_flags); + const CFX_PathData* LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width); + + + CFX_FaceCache(FXFT_Face face); +private: + FXFT_Face m_Face; + CFX_GlyphBitmap* RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, + const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); + CFX_GlyphBitmap* RenderGlyph_Nativetext(CFX_Font* pFont, FX_DWORD glyph_index, + const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); + CFX_GlyphBitmap* LookUpGlyphBitmap(CFX_Font* pFont, const CFX_AffineMatrix* pMatrix, CFX_ByteStringC& FaceGlyphsKey, + FX_DWORD glyph_index, FX_BOOL bFontStyle, int dest_width, int anti_alias); + CFX_MapByteStringToPtr m_SizeMap; + CFX_MapPtrToPtr m_PathMap; + CFX_DIBitmap* m_pBitmap; + void* m_pPlatformGraphics; + void* m_pPlatformBitmap; + void* m_hDC; + void* m_hBitmap; + void* m_hOldBitmap; + void* m_hGdiFont; + void* m_hOldGdiFont; + + void InitPlatform(); + void DestroyPlatform(); +}; +typedef struct { + const CFX_GlyphBitmap* m_pGlyph; + int m_OriginX, m_OriginY; + FX_FLOAT m_fOriginX, m_fOriginY; +} FXTEXT_GLYPHPOS; +FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars, int anti_alias, FX_FLOAT retinaScaleX = 1.0f, FX_FLOAT retinaScaleY = 1.0f); +FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size, + CFX_AffineMatrix* pMatrix, unsigned long glyph_index, unsigned long argb); +FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size, + CFX_AffineMatrix* pText_matrix, unsigned short const* text, unsigned long argb); +class IFX_GSUBTable +{ +public: + virtual void Release() = 0; + virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) = 0; +}; +IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont); +#endif diff --git a/core/include/fxge/fx_freetype.h b/core/include/fxge/fx_freetype.h index 397c3eea9b..6a2190b2fc 100644 --- a/core/include/fxge/fx_freetype.h +++ b/core/include/fxge/fx_freetype.h @@ -1,144 +1,144 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "../thirdparties/freetype/ft2build.h" -#include "../thirdparties/freetype/freetype/freetype.h" -#include "../thirdparties/freetype/freetype/ftoutln.h" -#include "../thirdparties/freetype/freetype/ftmm.h" -#include "../thirdparties/freetype/freetype/internal/ftobjs.h" -#include "../thirdparties/freetype/freetype/tttables.h" -#ifdef __cplusplus -extern "C" { -#endif -#define FXFT_ENCODING_UNICODE FT_ENCODING_UNICODE -#define FXFT_ENCODING_ADOBE_STANDARD FT_ENCODING_ADOBE_STANDARD -#define FXFT_ENCODING_ADOBE_EXPERT FT_ENCODING_ADOBE_EXPERT -#define FXFT_ENCODING_ADOBE_LATIN_1 FT_ENCODING_ADOBE_LATIN_1 -#define FXFT_ENCODING_APPLE_ROMAN FT_ENCODING_APPLE_ROMAN -#define FXFT_ENCODING_ADOBE_CUSTOM FT_ENCODING_ADOBE_CUSTOM -#define FXFT_ENCODING_MS_SYMBOL FT_ENCODING_MS_SYMBOL -#define FXFT_ENCODING_GB2312 FT_ENCODING_GB2312 -#define FXFT_ENCODING_BIG5 FT_ENCODING_BIG5 -#define FXFT_ENCODING_SJIS FT_ENCODING_SJIS -#define FXFT_ENCODING_JOHAB FT_ENCODING_JOHAB -#define FXFT_ENCODING_WANSUNG FT_ENCODING_WANSUNG -#define FXFT_LOAD_NO_SCALE FT_LOAD_NO_SCALE -#define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH -#define FXFT_RENDER_MODE_LCD FT_RENDER_MODE_LCD -#define FXFT_RENDER_MODE_MONO FT_RENDER_MODE_MONO -#define FXFT_RENDER_MODE_NORMAL FT_RENDER_MODE_NORMAL -#define FXFT_LOAD_IGNORE_TRANSFORM FT_LOAD_IGNORE_TRANSFORM -#define FXFT_LOAD_NO_BITMAP FT_LOAD_NO_BITMAP -#define FXFT_LOAD_NO_HINTING FT_LOAD_NO_HINTING -#define FXFT_PIXEL_MODE_MONO FT_PIXEL_MODE_MONO -#define FXFT_STYLE_FLAG_ITALIC FT_STYLE_FLAG_ITALIC -#define FXFT_STYLE_FLAG_BOLD FT_STYLE_FLAG_BOLD -#define FXFT_FACE_FLAG_SFNT FT_FACE_FLAG_SFNT -#define FXFT_FACE_FLAG_TRICKY ( 1L << 13 ) -typedef FT_MM_Var* FXFT_MM_Var; -typedef FT_Bitmap* FXFT_Bitmap; -#define FXFT_Matrix FT_Matrix -#define FXFT_Vector FT_Vector -#define FXFT_Outline_Funcs FT_Outline_Funcs -typedef FT_Open_Args FXFT_Open_Args; -typedef FT_StreamRec FXFT_StreamRec; -typedef FT_StreamRec* FXFT_Stream; -typedef FT_BBox FXFT_BBox; -typedef FT_Glyph FXFT_Glyph; -typedef FT_CharMap FXFT_CharMap; -#define FXFT_GLYPH_BBOX_PIXELS FT_GLYPH_BBOX_PIXELS -#define FXFT_Open_Face(library, args, index, face) \ - FT_Open_Face((FT_Library)(library), args, index, (FT_Face*)(face)) -#define FXFT_Done_Face(face) FT_Done_Face((FT_Face)(face)) -#define FXFT_Done_FreeType(library) FT_Done_FreeType((FT_Library)(library)) -#define FXFT_Init_FreeType(library) FT_Init_FreeType((FT_Library*)(library)) -#define FXFT_New_Memory_Face(library, base, size, index, face) \ - FT_New_Memory_Face((FT_Library)(library), base, size, index, (FT_Face*)(face)) -#define FXFT_New_Face(library, filename, index, face) \ - FT_New_Face((FT_Library)(library), filename, index, (FT_Face*)(face)) -#define FXFT_Get_Face_FreeType(face) ((FT_Face)face)->driver->root.library -#define FXFT_Select_Charmap(face, encoding) FT_Select_Charmap((FT_Face)face, (FT_Encoding)encoding) -#define FXFT_Set_Charmap(face, charmap) FT_Set_Charmap((FT_Face)face, (FT_CharMap)charmap) -#define FXFT_Load_Glyph(face, glyph_index, flags) FT_Load_Glyph((FT_Face)face, glyph_index, flags) -#define FXFT_Get_Char_Index(face, code) FT_Get_Char_Index((FT_Face)face, code) -#define FXFT_Get_Glyph_Name(face, index, buffer, size) FT_Get_Glyph_Name((FT_Face)face, index, buffer, size) -#define FXFT_Get_Name_Index(face, name) FT_Get_Name_Index((FT_Face)face, name) -#define FXFT_Has_Glyph_Names(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES) -#define FXFT_Get_Postscript_Name(face) FT_Get_Postscript_Name((FT_Face)face) -#define FXFT_Load_Sfnt_Table(face, tag, offset, buffer, length) \ - FT_Load_Sfnt_Table((FT_Face)face, tag, offset, buffer, length) -#define FXFT_Get_First_Char(face, glyph_index) FT_Get_First_Char((FT_Face)face, glyph_index) -#define FXFT_Get_Next_Char(face, code, glyph_index) FT_Get_Next_Char((FT_Face)face, code, glyph_index) -#define FXFT_Clear_Face_External_Stream(face) (((FT_Face)face)->face_flags&=~FT_FACE_FLAG_EXTERNAL_STREAM) -#define FXFT_Get_Face_External_Stream(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_EXTERNAL_STREAM) -#define FXFT_Is_Face_TT_OT(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_SFNT) -#define FXFT_Is_Face_Tricky(face) (((FT_Face)face)->face_flags&FXFT_FACE_FLAG_TRICKY) -#define FXFT_Is_Face_fixedwidth(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH) -#define FXFT_Get_Face_Stream_Base(face) ((FT_Face)face)->stream->base -#define FXFT_Get_Face_Stream_Size(face) ((FT_Face)face)->stream->size -#define FXFT_Get_Face_Family_Name(face) ((FT_Face)face)->family_name -#define FXFT_Get_Face_Style_Name(face) ((FT_Face)face)->style_name -#define FXFT_Get_Face_Numfaces(face) ((FT_Face)face)->num_faces -#define FXFT_Get_Face_Faceindex(face) ((FT_Face)face)->face_index -#define FXFT_Is_Face_Italic(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_ITALIC) -#define FXFT_Is_Face_Bold(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_BOLD) -#define FXFT_Get_Face_Charmaps(face) ((FT_Face)face)->charmaps -#define FXFT_Get_Glyph_HoriBearingX(face) ((FT_Face)face)->glyph->metrics.horiBearingX -#define FXFT_Get_Glyph_HoriBearingY(face) ((FT_Face)face)->glyph->metrics.horiBearingY -#define FXFT_Get_Glyph_Width(face) ((FT_Face)face)->glyph->metrics.width -#define FXFT_Get_Glyph_Height(face) ((FT_Face)face)->glyph->metrics.height -#define FXFT_Get_Face_CharmapCount(face) ((FT_Face)face)->num_charmaps -#define FXFT_Get_Charmap_Encoding(charmap) ((FT_CharMap)charmap)->encoding -#define FXFT_Get_Face_Charmap(face) ((FT_Face)face)->charmap -#define FXFT_Get_Charmap_PlatformID(charmap) ((FT_CharMap)charmap)->platform_id -#define FXFT_Get_Charmap_EncodingID(charmap) ((FT_CharMap)charmap)->encoding_id -#define FXFT_Get_Face_UnitsPerEM(face) ((FT_Face)face)->units_per_EM -#define FXFT_Get_Face_xMin(face) ((FT_Face)face)->bbox.xMin -#define FXFT_Get_Face_xMax(face) ((FT_Face)face)->bbox.xMax -#define FXFT_Get_Face_yMin(face) ((FT_Face)face)->bbox.yMin -#define FXFT_Get_Face_yMax(face) ((FT_Face)face)->bbox.yMax -#define FXFT_Get_Face_Height(face) ((FT_Face)face)->height -#define FXFT_Get_Face_UnderLineThickness(face) ((FT_Face)face)->underline_thickness -#define FXFT_Get_Face_UnderLinePosition(face) ((FT_Face)face)->underline_position -#define FXFT_Get_Face_MaxAdvanceWidth(face) ((FT_Face)face)->max_advance_width -#define FXFT_Get_Face_Ascender(face) ((FT_Face)face)->ascender -#define FXFT_Get_Face_Descender(face) ((FT_Face)face)->descender -#define FXFT_Get_Glyph_HoriAdvance(face) ((FT_Face)face)->glyph->metrics.horiAdvance -#define FXFT_Get_MM_Axis(var, index) &((FT_MM_Var*)var)->axis[index] -#define FXFT_Get_MM_Axis_Min(axis) ((FT_Var_Axis*)axis)->minimum -#define FXFT_Get_MM_Axis_Max(axis) ((FT_Var_Axis*)axis)->maximum -#define FXFT_Get_MM_Axis_Def(axis) ((FT_Var_Axis*)axis)->def -#define FXFT_Get_Face_Internal_Flag(face) ((FT_Face)face)->internal->transform_flags -#define FXFT_Set_Face_Internal_Flag(face, flag) (((FT_Face)face)->internal->transform_flags = flag) -#define FXFT_Alloc(library, size) ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size) -#define FXFT_Free(face, p) ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p) -#define FXFT_Get_Glyph_Outline(face) &((FT_Face)face)->glyph->outline -#define FXFT_Get_Outline_Bbox(outline, cbox) FT_Outline_Get_CBox(outline, cbox) -#define FXFT_Render_Glyph(face, mode) FT_Render_Glyph(((FT_Face)face)->glyph, (enum FT_Render_Mode_)mode) -#define FXFT_Get_MM_Var(face, p) FT_Get_MM_Var((FT_Face)face, p) -#define FXFT_Set_MM_Design_Coordinates(face, n, p) FT_Set_MM_Design_Coordinates((FT_Face)face, n, p) -#define FXFT_Set_Pixel_Sizes(face, w, h) FT_Set_Pixel_Sizes((FT_Face)face, w, h) -#define FXFT_Set_Transform(face, m, d) FT_Set_Transform((FT_Face)face, m, d) -#define FXFT_Outline_Embolden(outline, s) FT_Outline_Embolden(outline, s) -#define FXFT_Get_Glyph_Bitmap(face) &((FT_Face)face)->glyph->bitmap -#define FXFT_Get_Bitmap_Width(bitmap) ((FT_Bitmap*)bitmap)->width -#define FXFT_Get_Bitmap_Rows(bitmap) ((FT_Bitmap*)bitmap)->rows -#define FXFT_Get_Bitmap_PixelMode(bitmap) ((FT_Bitmap*)bitmap)->pixel_mode -#define FXFT_Get_Bitmap_Pitch(bitmap) ((FT_Bitmap*)bitmap)->pitch -#define FXFT_Get_Bitmap_Buffer(bitmap) ((FT_Bitmap*)bitmap)->buffer -#define FXFT_Get_Glyph_BitmapLeft(face) ((FT_Face)face)->glyph->bitmap_left -#define FXFT_Get_Glyph_BitmapTop(face) ((FT_Face)face)->glyph->bitmap_top -#define FXFT_Outline_Decompose(outline, funcs, params) FT_Outline_Decompose(outline, funcs, params) -#define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) FT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) -#define FXFT_Get_Glyph(slot, aglyph) FT_Get_Glyph(slot, aglyph) -#define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) FT_Glyph_Get_CBox(glyph, bbox_mode, acbox) -#define FXFT_Done_Glyph(glyph) FT_Done_Glyph(glyph) -#define FXFT_Library_SetLcdFilter(library, filter) FT_Library_SetLcdFilter((FT_Library)(library), filter) -int FXFT_unicode_from_adobe_name(const char* name); -void FXFT_adobe_name_from_unicode(char* name, unsigned int unicode); -#ifdef __cplusplus -}; -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "../thirdparties/freetype/ft2build.h" +#include "../thirdparties/freetype/freetype/freetype.h" +#include "../thirdparties/freetype/freetype/ftoutln.h" +#include "../thirdparties/freetype/freetype/ftmm.h" +#include "../thirdparties/freetype/freetype/internal/ftobjs.h" +#include "../thirdparties/freetype/freetype/tttables.h" +#ifdef __cplusplus +extern "C" { +#endif +#define FXFT_ENCODING_UNICODE FT_ENCODING_UNICODE +#define FXFT_ENCODING_ADOBE_STANDARD FT_ENCODING_ADOBE_STANDARD +#define FXFT_ENCODING_ADOBE_EXPERT FT_ENCODING_ADOBE_EXPERT +#define FXFT_ENCODING_ADOBE_LATIN_1 FT_ENCODING_ADOBE_LATIN_1 +#define FXFT_ENCODING_APPLE_ROMAN FT_ENCODING_APPLE_ROMAN +#define FXFT_ENCODING_ADOBE_CUSTOM FT_ENCODING_ADOBE_CUSTOM +#define FXFT_ENCODING_MS_SYMBOL FT_ENCODING_MS_SYMBOL +#define FXFT_ENCODING_GB2312 FT_ENCODING_GB2312 +#define FXFT_ENCODING_BIG5 FT_ENCODING_BIG5 +#define FXFT_ENCODING_SJIS FT_ENCODING_SJIS +#define FXFT_ENCODING_JOHAB FT_ENCODING_JOHAB +#define FXFT_ENCODING_WANSUNG FT_ENCODING_WANSUNG +#define FXFT_LOAD_NO_SCALE FT_LOAD_NO_SCALE +#define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH +#define FXFT_RENDER_MODE_LCD FT_RENDER_MODE_LCD +#define FXFT_RENDER_MODE_MONO FT_RENDER_MODE_MONO +#define FXFT_RENDER_MODE_NORMAL FT_RENDER_MODE_NORMAL +#define FXFT_LOAD_IGNORE_TRANSFORM FT_LOAD_IGNORE_TRANSFORM +#define FXFT_LOAD_NO_BITMAP FT_LOAD_NO_BITMAP +#define FXFT_LOAD_NO_HINTING FT_LOAD_NO_HINTING +#define FXFT_PIXEL_MODE_MONO FT_PIXEL_MODE_MONO +#define FXFT_STYLE_FLAG_ITALIC FT_STYLE_FLAG_ITALIC +#define FXFT_STYLE_FLAG_BOLD FT_STYLE_FLAG_BOLD +#define FXFT_FACE_FLAG_SFNT FT_FACE_FLAG_SFNT +#define FXFT_FACE_FLAG_TRICKY ( 1L << 13 ) +typedef FT_MM_Var* FXFT_MM_Var; +typedef FT_Bitmap* FXFT_Bitmap; +#define FXFT_Matrix FT_Matrix +#define FXFT_Vector FT_Vector +#define FXFT_Outline_Funcs FT_Outline_Funcs +typedef FT_Open_Args FXFT_Open_Args; +typedef FT_StreamRec FXFT_StreamRec; +typedef FT_StreamRec* FXFT_Stream; +typedef FT_BBox FXFT_BBox; +typedef FT_Glyph FXFT_Glyph; +typedef FT_CharMap FXFT_CharMap; +#define FXFT_GLYPH_BBOX_PIXELS FT_GLYPH_BBOX_PIXELS +#define FXFT_Open_Face(library, args, index, face) \ + FT_Open_Face((FT_Library)(library), args, index, (FT_Face*)(face)) +#define FXFT_Done_Face(face) FT_Done_Face((FT_Face)(face)) +#define FXFT_Done_FreeType(library) FT_Done_FreeType((FT_Library)(library)) +#define FXFT_Init_FreeType(library) FT_Init_FreeType((FT_Library*)(library)) +#define FXFT_New_Memory_Face(library, base, size, index, face) \ + FT_New_Memory_Face((FT_Library)(library), base, size, index, (FT_Face*)(face)) +#define FXFT_New_Face(library, filename, index, face) \ + FT_New_Face((FT_Library)(library), filename, index, (FT_Face*)(face)) +#define FXFT_Get_Face_FreeType(face) ((FT_Face)face)->driver->root.library +#define FXFT_Select_Charmap(face, encoding) FT_Select_Charmap((FT_Face)face, (FT_Encoding)encoding) +#define FXFT_Set_Charmap(face, charmap) FT_Set_Charmap((FT_Face)face, (FT_CharMap)charmap) +#define FXFT_Load_Glyph(face, glyph_index, flags) FT_Load_Glyph((FT_Face)face, glyph_index, flags) +#define FXFT_Get_Char_Index(face, code) FT_Get_Char_Index((FT_Face)face, code) +#define FXFT_Get_Glyph_Name(face, index, buffer, size) FT_Get_Glyph_Name((FT_Face)face, index, buffer, size) +#define FXFT_Get_Name_Index(face, name) FT_Get_Name_Index((FT_Face)face, name) +#define FXFT_Has_Glyph_Names(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES) +#define FXFT_Get_Postscript_Name(face) FT_Get_Postscript_Name((FT_Face)face) +#define FXFT_Load_Sfnt_Table(face, tag, offset, buffer, length) \ + FT_Load_Sfnt_Table((FT_Face)face, tag, offset, buffer, length) +#define FXFT_Get_First_Char(face, glyph_index) FT_Get_First_Char((FT_Face)face, glyph_index) +#define FXFT_Get_Next_Char(face, code, glyph_index) FT_Get_Next_Char((FT_Face)face, code, glyph_index) +#define FXFT_Clear_Face_External_Stream(face) (((FT_Face)face)->face_flags&=~FT_FACE_FLAG_EXTERNAL_STREAM) +#define FXFT_Get_Face_External_Stream(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_EXTERNAL_STREAM) +#define FXFT_Is_Face_TT_OT(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_SFNT) +#define FXFT_Is_Face_Tricky(face) (((FT_Face)face)->face_flags&FXFT_FACE_FLAG_TRICKY) +#define FXFT_Is_Face_fixedwidth(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH) +#define FXFT_Get_Face_Stream_Base(face) ((FT_Face)face)->stream->base +#define FXFT_Get_Face_Stream_Size(face) ((FT_Face)face)->stream->size +#define FXFT_Get_Face_Family_Name(face) ((FT_Face)face)->family_name +#define FXFT_Get_Face_Style_Name(face) ((FT_Face)face)->style_name +#define FXFT_Get_Face_Numfaces(face) ((FT_Face)face)->num_faces +#define FXFT_Get_Face_Faceindex(face) ((FT_Face)face)->face_index +#define FXFT_Is_Face_Italic(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_ITALIC) +#define FXFT_Is_Face_Bold(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_BOLD) +#define FXFT_Get_Face_Charmaps(face) ((FT_Face)face)->charmaps +#define FXFT_Get_Glyph_HoriBearingX(face) ((FT_Face)face)->glyph->metrics.horiBearingX +#define FXFT_Get_Glyph_HoriBearingY(face) ((FT_Face)face)->glyph->metrics.horiBearingY +#define FXFT_Get_Glyph_Width(face) ((FT_Face)face)->glyph->metrics.width +#define FXFT_Get_Glyph_Height(face) ((FT_Face)face)->glyph->metrics.height +#define FXFT_Get_Face_CharmapCount(face) ((FT_Face)face)->num_charmaps +#define FXFT_Get_Charmap_Encoding(charmap) ((FT_CharMap)charmap)->encoding +#define FXFT_Get_Face_Charmap(face) ((FT_Face)face)->charmap +#define FXFT_Get_Charmap_PlatformID(charmap) ((FT_CharMap)charmap)->platform_id +#define FXFT_Get_Charmap_EncodingID(charmap) ((FT_CharMap)charmap)->encoding_id +#define FXFT_Get_Face_UnitsPerEM(face) ((FT_Face)face)->units_per_EM +#define FXFT_Get_Face_xMin(face) ((FT_Face)face)->bbox.xMin +#define FXFT_Get_Face_xMax(face) ((FT_Face)face)->bbox.xMax +#define FXFT_Get_Face_yMin(face) ((FT_Face)face)->bbox.yMin +#define FXFT_Get_Face_yMax(face) ((FT_Face)face)->bbox.yMax +#define FXFT_Get_Face_Height(face) ((FT_Face)face)->height +#define FXFT_Get_Face_UnderLineThickness(face) ((FT_Face)face)->underline_thickness +#define FXFT_Get_Face_UnderLinePosition(face) ((FT_Face)face)->underline_position +#define FXFT_Get_Face_MaxAdvanceWidth(face) ((FT_Face)face)->max_advance_width +#define FXFT_Get_Face_Ascender(face) ((FT_Face)face)->ascender +#define FXFT_Get_Face_Descender(face) ((FT_Face)face)->descender +#define FXFT_Get_Glyph_HoriAdvance(face) ((FT_Face)face)->glyph->metrics.horiAdvance +#define FXFT_Get_MM_Axis(var, index) &((FT_MM_Var*)var)->axis[index] +#define FXFT_Get_MM_Axis_Min(axis) ((FT_Var_Axis*)axis)->minimum +#define FXFT_Get_MM_Axis_Max(axis) ((FT_Var_Axis*)axis)->maximum +#define FXFT_Get_MM_Axis_Def(axis) ((FT_Var_Axis*)axis)->def +#define FXFT_Get_Face_Internal_Flag(face) ((FT_Face)face)->internal->transform_flags +#define FXFT_Set_Face_Internal_Flag(face, flag) (((FT_Face)face)->internal->transform_flags = flag) +#define FXFT_Alloc(library, size) ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size) +#define FXFT_Free(face, p) ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p) +#define FXFT_Get_Glyph_Outline(face) &((FT_Face)face)->glyph->outline +#define FXFT_Get_Outline_Bbox(outline, cbox) FT_Outline_Get_CBox(outline, cbox) +#define FXFT_Render_Glyph(face, mode) FT_Render_Glyph(((FT_Face)face)->glyph, (enum FT_Render_Mode_)mode) +#define FXFT_Get_MM_Var(face, p) FT_Get_MM_Var((FT_Face)face, p) +#define FXFT_Set_MM_Design_Coordinates(face, n, p) FT_Set_MM_Design_Coordinates((FT_Face)face, n, p) +#define FXFT_Set_Pixel_Sizes(face, w, h) FT_Set_Pixel_Sizes((FT_Face)face, w, h) +#define FXFT_Set_Transform(face, m, d) FT_Set_Transform((FT_Face)face, m, d) +#define FXFT_Outline_Embolden(outline, s) FT_Outline_Embolden(outline, s) +#define FXFT_Get_Glyph_Bitmap(face) &((FT_Face)face)->glyph->bitmap +#define FXFT_Get_Bitmap_Width(bitmap) ((FT_Bitmap*)bitmap)->width +#define FXFT_Get_Bitmap_Rows(bitmap) ((FT_Bitmap*)bitmap)->rows +#define FXFT_Get_Bitmap_PixelMode(bitmap) ((FT_Bitmap*)bitmap)->pixel_mode +#define FXFT_Get_Bitmap_Pitch(bitmap) ((FT_Bitmap*)bitmap)->pitch +#define FXFT_Get_Bitmap_Buffer(bitmap) ((FT_Bitmap*)bitmap)->buffer +#define FXFT_Get_Glyph_BitmapLeft(face) ((FT_Face)face)->glyph->bitmap_left +#define FXFT_Get_Glyph_BitmapTop(face) ((FT_Face)face)->glyph->bitmap_top +#define FXFT_Outline_Decompose(outline, funcs, params) FT_Outline_Decompose(outline, funcs, params) +#define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) FT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) +#define FXFT_Get_Glyph(slot, aglyph) FT_Get_Glyph(slot, aglyph) +#define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) FT_Glyph_Get_CBox(glyph, bbox_mode, acbox) +#define FXFT_Done_Glyph(glyph) FT_Done_Glyph(glyph) +#define FXFT_Library_SetLcdFilter(library, filter) FT_Library_SetLcdFilter((FT_Library)(library), filter) +int FXFT_unicode_from_adobe_name(const char* name); +void FXFT_adobe_name_from_unicode(char* name, unsigned int unicode); +#ifdef __cplusplus +}; +#endif diff --git a/core/include/fxge/fx_ge.h b/core/include/fxge/fx_ge.h index ab0bf3572a..82719ffda6 100644 --- a/core/include/fxge/fx_ge.h +++ b/core/include/fxge/fx_ge.h @@ -1,733 +1,733 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _FX_GE_H_ -#define _FX_GE_H_ -#ifndef _FX_DIB_H_ -#include "fx_dib.h" -#endif -#ifndef _FX_FONT_H_ -#include "fx_font.h" -#endif -class CFX_ClipRgn; -class CFX_PathData; -class CFX_GraphStateData; -class CFX_Font; -class CFX_FontMgr; -class CFX_FontCache; -class CFX_FaceCache; -class CFX_RenderDevice; -class IFX_RenderDeviceDriver; -class CCodec_ModuleMgr; -class IFXG_PaintModuleMgr; -class CFX_GEModule : public CFX_Object -{ -public: - - static void Create(); - - static void Use(CFX_GEModule* pMgr); - - static CFX_GEModule* Get(); - - static void Destroy(); -public: - - CFX_FontCache* GetFontCache(); - CFX_FontMgr* GetFontMgr() - { - return m_pFontMgr; - } - void SetTextGamma(FX_FLOAT gammaValue); - FX_LPCBYTE GetTextGammaTable(); - void SetExtFontMapper(IFX_FontMapper* pFontMapper); - - void SetCodecModule(CCodec_ModuleMgr* pCodecModule) - { - m_pCodecModule = pCodecModule; - } - CCodec_ModuleMgr* GetCodecModule() - { - return m_pCodecModule; - } - FXFT_Library m_FTLibrary; - void* GetPlatformData() - { - return m_pPlatformData; - } -protected: - - CFX_GEModule(); - - ~CFX_GEModule(); - void InitPlatform(); - void DestroyPlatform(); -private: - FX_BYTE m_GammaValue[256]; - CFX_FontCache* m_pFontCache; - CFX_FontMgr* m_pFontMgr; - CCodec_ModuleMgr* m_pCodecModule; - void* m_pPlatformData; -}; -typedef struct { - - FX_FLOAT m_PointX; - - FX_FLOAT m_PointY; - - int m_Flag; -} FX_PATHPOINT; -#define FXPT_CLOSEFIGURE 0x01 -#define FXPT_LINETO 0x02 -#define FXPT_BEZIERTO 0x04 -#define FXPT_MOVETO 0x06 -#define FXPT_TYPE 0x06 -#define FXFILL_ALTERNATE 1 -#define FXFILL_WINDING 2 -class CFX_ClipRgn : public CFX_Object -{ -public: - - CFX_ClipRgn(int device_width, int device_height); - - CFX_ClipRgn(const FX_RECT& rect); - - CFX_ClipRgn(const CFX_ClipRgn& src); - - ~CFX_ClipRgn(); - - typedef enum { - RectI, - MaskF - } ClipType; - - void Reset(const FX_RECT& rect); - - ClipType GetType() const - { - return m_Type; - } - - const FX_RECT& GetBox() const - { - return m_Box; - } - - CFX_DIBitmapRef GetMask() const - { - return m_Mask; - } - - void IntersectRect(const FX_RECT& rect); - - void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask); -protected: - - ClipType m_Type; - - FX_RECT m_Box; - - CFX_DIBitmapRef m_Mask; - - void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask); -}; -extern const FX_BYTE g_GammaRamp[256]; -extern const FX_BYTE g_GammaInverse[256]; -#define FX_GAMMA(value) (value) -#define FX_GAMMA_INVERSE(value) (value) -inline FX_ARGB ArgbGamma(FX_ARGB argb) -{ - return argb; -} -inline FX_ARGB ArgbGammaInverse(FX_ARGB argb) -{ - return argb; -} -class CFX_PathData : public CFX_Object -{ -public: - - CFX_PathData(); - - CFX_PathData(const CFX_PathData& src); - - ~CFX_PathData(); - - - - - int GetPointCount() const - { - return m_PointCount; - } - - int GetFlag(int index) const - { - return m_pPoints[index].m_Flag; - } - - FX_FLOAT GetPointX(int index) const - { - return m_pPoints[index].m_PointX; - } - - FX_FLOAT GetPointY(int index) const - { - return m_pPoints[index].m_PointY; - } - - - - FX_PATHPOINT* GetPoints() const - { - return m_pPoints; - } - - FX_BOOL SetPointCount(int nPoints); - - FX_BOOL AllocPointCount(int nPoints); - - FX_BOOL AddPointCount(int addPoints); - - CFX_FloatRect GetBoundingBox() const; - - CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const; - - void Transform(const CFX_AffineMatrix* pMatrix); - - FX_BOOL IsRect() const; - - FX_BOOL GetZeroAreaPath(CFX_PathData& NewPath, CFX_AffineMatrix* pMatrix, FX_BOOL&bThin, FX_BOOL bAdjust) const; - - FX_BOOL IsRect(const CFX_AffineMatrix* pMatrix, CFX_FloatRect* rect) const; - - FX_BOOL Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix); - - FX_BOOL AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top); - - void SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag); - - void TrimPoints(int nPoints); - - FX_BOOL Copy(const CFX_PathData &src); -protected: - friend class CPDF_Path; - - int m_PointCount; - - FX_PATHPOINT* m_pPoints; - - int m_AllocCount; -}; -class CFX_GraphStateData : public CFX_Object -{ -public: - - CFX_GraphStateData(); - - CFX_GraphStateData(const CFX_GraphStateData& src); - - ~CFX_GraphStateData(); - - void Copy(const CFX_GraphStateData& src); - - void SetDashCount(int count); - - - - typedef enum { - LineCapButt = 0, - LineCapRound = 1, - LineCapSquare = 2 - } LineCap; - LineCap m_LineCap; - int m_DashCount; - FX_FLOAT* m_DashArray; - FX_FLOAT m_DashPhase; - - typedef enum { - LineJoinMiter = 0, - LineJoinRound = 1, - LineJoinBevel = 2, - } LineJoin; - LineJoin m_LineJoin; - FX_FLOAT m_MiterLimit; - FX_FLOAT m_LineWidth; - -}; -#define FXDC_DEVICE_CLASS 1 -#define FXDC_PIXEL_WIDTH 2 -#define FXDC_PIXEL_HEIGHT 3 -#define FXDC_BITS_PIXEL 4 -#define FXDC_HORZ_SIZE 5 -#define FXDC_VERT_SIZE 6 -#define FXDC_RENDER_CAPS 7 -#define FXDC_DITHER_BITS 8 -#define FXDC_DISPLAY 1 -#define FXDC_PRINTER 2 -#define FXRC_GET_BITS 0x01 -#define FXRC_BIT_MASK 0x02 -#define FXRC_ALPHA_MASK 0x04 -#define FXRC_ALPHA_PATH 0x10 -#define FXRC_ALPHA_IMAGE 0x20 -#define FXRC_ALPHA_OUTPUT 0x40 -#define FXRC_BLEND_MODE 0x80 -#define FXRC_SOFT_CLIP 0x100 -#define FXRC_CMYK_OUTPUT 0x200 -#define FXRC_BITMASK_OUTPUT 0x400 -#define FXRC_BYTEMASK_OUTPUT 0x800 -#define FXRENDER_IMAGE_LOSSY 0x1000 -#define FXFILL_ALTERNATE 1 -#define FXFILL_WINDING 2 -#define FXFILL_FULLCOVER 4 -#define FXFILL_RECT_AA 8 -#define FX_FILL_STROKE 16 -#define FX_STROKE_ADJUST 32 -#define FX_STROKE_TEXT_MODE 64 -#define FX_FILL_TEXT_MODE 128 -#define FX_ZEROAREA_FILL 256 -#define FXFILL_NOPATHSMOOTH 512 -#define FXTEXT_CLEARTYPE 0x01 -#define FXTEXT_BGR_STRIPE 0x02 -#define FXTEXT_PRINTGRAPHICTEXT 0x04 -#define FXTEXT_NO_NATIVETEXT 0x08 -#define FXTEXT_PRINTIMAGETEXT 0x10 -#define FXTEXT_NOSMOOTH 0x20 -typedef struct { - FX_DWORD m_GlyphIndex; - FX_FLOAT m_OriginX, m_OriginY; - int m_FontCharWidth; - FX_BOOL m_bGlyphAdjust; - FX_FLOAT m_AdjustMatrix[4]; - FX_DWORD m_ExtGID; - FX_BOOL m_bFontStyle; -} FXTEXT_CHARPOS; -class CFX_RenderDevice : public CFX_Object -{ -public: - CFX_RenderDevice(); - - virtual ~CFX_RenderDevice(); - - void SetDeviceDriver(IFX_RenderDeviceDriver* pDriver); - - IFX_RenderDeviceDriver* GetDeviceDriver() const - { - return m_pDeviceDriver; - } - - FX_BOOL StartRendering(); - - void EndRendering(); - - - - void SaveState(); - - void RestoreState(FX_BOOL bKeepSaved = FALSE); - - - - - int GetWidth() const - { - return m_Width; - } - - int GetHeight() const - { - return m_Height; - } - - int GetDeviceClass() const - { - return m_DeviceClass; - } - - int GetBPP() const - { - return m_bpp; - } - - int GetRenderCaps() const - { - return m_RenderCaps; - } - - int GetDeviceCaps(int id) const; - - CFX_Matrix GetCTM() const; - - - CFX_DIBitmap* GetBitmap() const - { - return m_pBitmap; - } - void SetBitmap(CFX_DIBitmap* pBitmap) - { - m_pBitmap = pBitmap; - } - - FX_BOOL CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const; - - const FX_RECT& GetClipBox() const - { - return m_ClipBox; - } - - FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - int fill_mode - ); - - FX_BOOL SetClip_Rect(const FX_RECT* pRect); - - FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ); - - FX_BOOL DrawPath(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL - ); - - FX_BOOL SetPixel(int x, int y, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, - int fill_mode = 0, int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL); - - CFX_DIBitmap* GetBackDrop(); - - FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, int left, int top, int blend_type = FXDIB_BLEND_NORMAL, - void* pIccTransform = NULL); - - FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, - FX_DWORD flags = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL StretchBitMask(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, - FX_DWORD color, FX_DWORD flags = 0, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause); - - void CancelDIBits(FX_LPVOID handle); - - FX_BOOL DrawNormalText(int nChars, const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, CFX_FontCache* pCache, - FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device, - FX_DWORD fill_color, FX_DWORD text_flags, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL DrawTextPath(int nChars, const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, CFX_FontCache* pCache, - FX_FLOAT font_size, const CFX_AffineMatrix* pText2User, - const CFX_AffineMatrix* pUser2Device, const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, FX_DWORD stroke_color, CFX_PathData* pClippingPath, int nFlag = 0, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - virtual void Begin() {} - virtual void End() {} -private: - - CFX_DIBitmap* m_pBitmap; - - - - int m_Width; - - int m_Height; - - int m_bpp; - - int m_RenderCaps; - - int m_DeviceClass; - - FX_RECT m_ClipBox; - -protected: - - IFX_RenderDeviceDriver* m_pDeviceDriver; -private: - - void InitDeviceInfo(); - - void UpdateClipBox(); -}; -class CFX_FxgeDevice : public CFX_RenderDevice -{ -public: - - CFX_FxgeDevice(); - - ~CFX_FxgeDevice(); - - FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); - - FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); -protected: - - FX_BOOL m_bOwnedBitmap; -}; -class CFX_SkiaDevice : public CFX_RenderDevice -{ -public: - - CFX_SkiaDevice(); - - ~CFX_SkiaDevice(); - - FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); - - FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); -protected: - - FX_BOOL m_bOwnedBitmap; -}; -class IFX_RenderDeviceDriver : public CFX_Object -{ -public: - - static IFX_RenderDeviceDriver* CreateFxgeDriver(CFX_DIBitmap* pBitmap, FX_BOOL bRgbByteOrder = FALSE, - CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); - - virtual ~IFX_RenderDeviceDriver() {} - virtual void Begin() { } - virtual void End() { } - - virtual int GetDeviceCaps(int caps_id) = 0; - - virtual CFX_Matrix GetCTM() const - { - return CFX_Matrix(); - } - - virtual FX_BOOL IsPSPrintDriver() - { - return FALSE; - } - - virtual FX_BOOL StartRendering() - { - return TRUE; - } - - virtual void EndRendering() {} - - - - - virtual void SaveState() = 0; - - virtual void RestoreState(FX_BOOL bKeepSaved = FALSE) = 0; - - - virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - int fill_mode - ) = 0; - - virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ) - { - return FALSE; - } - - virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL - ) = 0; - - virtual FX_BOOL SetPixel(int x, int y, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL) - { - return FALSE; - } - - virtual FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD fill_color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) - { - return FALSE; - } - - virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) - { - return FALSE; - } - - virtual FX_BOOL GetClipBox(FX_RECT* pRect) = 0; - - virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL, FX_BOOL bDEdge = FALSE) - { - return FALSE; - } - virtual CFX_DIBitmap* GetBackDrop() - { - return NULL; - } - - virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, - int dest_left, int dest_top, int blend_type, - int alpha_flag = 0, void* pIccTransform = NULL) = 0; - - virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; - - virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; - - virtual FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) - { - return FALSE; - } - - virtual void CancelDIBits(FX_LPVOID handle) {} - - virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, - CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL) - { - return FALSE; - } - - virtual void* GetPlatformSurface() - { - return NULL; - } - - virtual int GetDriverType() - { - return 0; - } - - virtual void ClearDriver() {} -}; -class IFX_PSOutput -{ -public: - - virtual void OutputPS(FX_LPCSTR string, int len) = 0; - virtual void Release() = 0; -}; -class CPSFont; -class CFX_PSRenderer : public CFX_Object -{ -public: - - CFX_PSRenderer(); - - ~CFX_PSRenderer(); - - void Init(IFX_PSOutput* pOutput, int ps_level, int width, int height, FX_BOOL bCmykOutput); - FX_BOOL StartRendering(); - void EndRendering(); - - void SaveState(); - - void RestoreState(FX_BOOL bKeepSaved = FALSE); - - void SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - int fill_mode - ); - - void SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ); - - FX_RECT GetClipBox() - { - return m_ClipBox; - } - - FX_BOOL DrawPath(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL - ); - - FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int dest_width, int dest_height, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL DrawDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, CFX_FontCache* pCache, - const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); -private: - - IFX_PSOutput* m_pOutput; - - int m_PSLevel; - - CFX_GraphStateData m_CurGraphState; - - FX_BOOL m_bGraphStateSet; - - FX_BOOL m_bCmykOutput; - - FX_BOOL m_bColorSet; - - FX_DWORD m_LastColor; - - FX_RECT m_ClipBox; - - CFX_ArrayTemplate m_PSFontList; - - CFX_ArrayTemplate m_ClipBoxStack; - FX_BOOL m_bInited; - - void OutputPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device); - - void SetGraphState(const CFX_GraphStateData* pGraphState); - - void SetColor(FX_DWORD color, int alpha_flag, void* pIccTransform); - - void FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont, const FXTEXT_CHARPOS& charpos, int& ps_fontnum, int &ps_glyphindex); - - void WritePSBinary(FX_LPCBYTE data, int len); -}; -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FX_GE_H_ +#define _FX_GE_H_ +#ifndef _FX_DIB_H_ +#include "fx_dib.h" +#endif +#ifndef _FX_FONT_H_ +#include "fx_font.h" +#endif +class CFX_ClipRgn; +class CFX_PathData; +class CFX_GraphStateData; +class CFX_Font; +class CFX_FontMgr; +class CFX_FontCache; +class CFX_FaceCache; +class CFX_RenderDevice; +class IFX_RenderDeviceDriver; +class CCodec_ModuleMgr; +class IFXG_PaintModuleMgr; +class CFX_GEModule : public CFX_Object +{ +public: + + static void Create(); + + static void Use(CFX_GEModule* pMgr); + + static CFX_GEModule* Get(); + + static void Destroy(); +public: + + CFX_FontCache* GetFontCache(); + CFX_FontMgr* GetFontMgr() + { + return m_pFontMgr; + } + void SetTextGamma(FX_FLOAT gammaValue); + FX_LPCBYTE GetTextGammaTable(); + void SetExtFontMapper(IFX_FontMapper* pFontMapper); + + void SetCodecModule(CCodec_ModuleMgr* pCodecModule) + { + m_pCodecModule = pCodecModule; + } + CCodec_ModuleMgr* GetCodecModule() + { + return m_pCodecModule; + } + FXFT_Library m_FTLibrary; + void* GetPlatformData() + { + return m_pPlatformData; + } +protected: + + CFX_GEModule(); + + ~CFX_GEModule(); + void InitPlatform(); + void DestroyPlatform(); +private: + FX_BYTE m_GammaValue[256]; + CFX_FontCache* m_pFontCache; + CFX_FontMgr* m_pFontMgr; + CCodec_ModuleMgr* m_pCodecModule; + void* m_pPlatformData; +}; +typedef struct { + + FX_FLOAT m_PointX; + + FX_FLOAT m_PointY; + + int m_Flag; +} FX_PATHPOINT; +#define FXPT_CLOSEFIGURE 0x01 +#define FXPT_LINETO 0x02 +#define FXPT_BEZIERTO 0x04 +#define FXPT_MOVETO 0x06 +#define FXPT_TYPE 0x06 +#define FXFILL_ALTERNATE 1 +#define FXFILL_WINDING 2 +class CFX_ClipRgn : public CFX_Object +{ +public: + + CFX_ClipRgn(int device_width, int device_height); + + CFX_ClipRgn(const FX_RECT& rect); + + CFX_ClipRgn(const CFX_ClipRgn& src); + + ~CFX_ClipRgn(); + + typedef enum { + RectI, + MaskF + } ClipType; + + void Reset(const FX_RECT& rect); + + ClipType GetType() const + { + return m_Type; + } + + const FX_RECT& GetBox() const + { + return m_Box; + } + + CFX_DIBitmapRef GetMask() const + { + return m_Mask; + } + + void IntersectRect(const FX_RECT& rect); + + void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask); +protected: + + ClipType m_Type; + + FX_RECT m_Box; + + CFX_DIBitmapRef m_Mask; + + void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask); +}; +extern const FX_BYTE g_GammaRamp[256]; +extern const FX_BYTE g_GammaInverse[256]; +#define FX_GAMMA(value) (value) +#define FX_GAMMA_INVERSE(value) (value) +inline FX_ARGB ArgbGamma(FX_ARGB argb) +{ + return argb; +} +inline FX_ARGB ArgbGammaInverse(FX_ARGB argb) +{ + return argb; +} +class CFX_PathData : public CFX_Object +{ +public: + + CFX_PathData(); + + CFX_PathData(const CFX_PathData& src); + + ~CFX_PathData(); + + + + + int GetPointCount() const + { + return m_PointCount; + } + + int GetFlag(int index) const + { + return m_pPoints[index].m_Flag; + } + + FX_FLOAT GetPointX(int index) const + { + return m_pPoints[index].m_PointX; + } + + FX_FLOAT GetPointY(int index) const + { + return m_pPoints[index].m_PointY; + } + + + + FX_PATHPOINT* GetPoints() const + { + return m_pPoints; + } + + FX_BOOL SetPointCount(int nPoints); + + FX_BOOL AllocPointCount(int nPoints); + + FX_BOOL AddPointCount(int addPoints); + + CFX_FloatRect GetBoundingBox() const; + + CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const; + + void Transform(const CFX_AffineMatrix* pMatrix); + + FX_BOOL IsRect() const; + + FX_BOOL GetZeroAreaPath(CFX_PathData& NewPath, CFX_AffineMatrix* pMatrix, FX_BOOL&bThin, FX_BOOL bAdjust) const; + + FX_BOOL IsRect(const CFX_AffineMatrix* pMatrix, CFX_FloatRect* rect) const; + + FX_BOOL Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix); + + FX_BOOL AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top); + + void SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag); + + void TrimPoints(int nPoints); + + FX_BOOL Copy(const CFX_PathData &src); +protected: + friend class CPDF_Path; + + int m_PointCount; + + FX_PATHPOINT* m_pPoints; + + int m_AllocCount; +}; +class CFX_GraphStateData : public CFX_Object +{ +public: + + CFX_GraphStateData(); + + CFX_GraphStateData(const CFX_GraphStateData& src); + + ~CFX_GraphStateData(); + + void Copy(const CFX_GraphStateData& src); + + void SetDashCount(int count); + + + + typedef enum { + LineCapButt = 0, + LineCapRound = 1, + LineCapSquare = 2 + } LineCap; + LineCap m_LineCap; + int m_DashCount; + FX_FLOAT* m_DashArray; + FX_FLOAT m_DashPhase; + + typedef enum { + LineJoinMiter = 0, + LineJoinRound = 1, + LineJoinBevel = 2, + } LineJoin; + LineJoin m_LineJoin; + FX_FLOAT m_MiterLimit; + FX_FLOAT m_LineWidth; + +}; +#define FXDC_DEVICE_CLASS 1 +#define FXDC_PIXEL_WIDTH 2 +#define FXDC_PIXEL_HEIGHT 3 +#define FXDC_BITS_PIXEL 4 +#define FXDC_HORZ_SIZE 5 +#define FXDC_VERT_SIZE 6 +#define FXDC_RENDER_CAPS 7 +#define FXDC_DITHER_BITS 8 +#define FXDC_DISPLAY 1 +#define FXDC_PRINTER 2 +#define FXRC_GET_BITS 0x01 +#define FXRC_BIT_MASK 0x02 +#define FXRC_ALPHA_MASK 0x04 +#define FXRC_ALPHA_PATH 0x10 +#define FXRC_ALPHA_IMAGE 0x20 +#define FXRC_ALPHA_OUTPUT 0x40 +#define FXRC_BLEND_MODE 0x80 +#define FXRC_SOFT_CLIP 0x100 +#define FXRC_CMYK_OUTPUT 0x200 +#define FXRC_BITMASK_OUTPUT 0x400 +#define FXRC_BYTEMASK_OUTPUT 0x800 +#define FXRENDER_IMAGE_LOSSY 0x1000 +#define FXFILL_ALTERNATE 1 +#define FXFILL_WINDING 2 +#define FXFILL_FULLCOVER 4 +#define FXFILL_RECT_AA 8 +#define FX_FILL_STROKE 16 +#define FX_STROKE_ADJUST 32 +#define FX_STROKE_TEXT_MODE 64 +#define FX_FILL_TEXT_MODE 128 +#define FX_ZEROAREA_FILL 256 +#define FXFILL_NOPATHSMOOTH 512 +#define FXTEXT_CLEARTYPE 0x01 +#define FXTEXT_BGR_STRIPE 0x02 +#define FXTEXT_PRINTGRAPHICTEXT 0x04 +#define FXTEXT_NO_NATIVETEXT 0x08 +#define FXTEXT_PRINTIMAGETEXT 0x10 +#define FXTEXT_NOSMOOTH 0x20 +typedef struct { + FX_DWORD m_GlyphIndex; + FX_FLOAT m_OriginX, m_OriginY; + int m_FontCharWidth; + FX_BOOL m_bGlyphAdjust; + FX_FLOAT m_AdjustMatrix[4]; + FX_DWORD m_ExtGID; + FX_BOOL m_bFontStyle; +} FXTEXT_CHARPOS; +class CFX_RenderDevice : public CFX_Object +{ +public: + CFX_RenderDevice(); + + virtual ~CFX_RenderDevice(); + + void SetDeviceDriver(IFX_RenderDeviceDriver* pDriver); + + IFX_RenderDeviceDriver* GetDeviceDriver() const + { + return m_pDeviceDriver; + } + + FX_BOOL StartRendering(); + + void EndRendering(); + + + + void SaveState(); + + void RestoreState(FX_BOOL bKeepSaved = FALSE); + + + + + int GetWidth() const + { + return m_Width; + } + + int GetHeight() const + { + return m_Height; + } + + int GetDeviceClass() const + { + return m_DeviceClass; + } + + int GetBPP() const + { + return m_bpp; + } + + int GetRenderCaps() const + { + return m_RenderCaps; + } + + int GetDeviceCaps(int id) const; + + CFX_Matrix GetCTM() const; + + + CFX_DIBitmap* GetBitmap() const + { + return m_pBitmap; + } + void SetBitmap(CFX_DIBitmap* pBitmap) + { + m_pBitmap = pBitmap; + } + + FX_BOOL CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const; + + const FX_RECT& GetClipBox() const + { + return m_ClipBox; + } + + FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode + ); + + FX_BOOL SetClip_Rect(const FX_RECT* pRect); + + FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState + ); + + FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL + ); + + FX_BOOL SetPixel(int x, int y, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, + int fill_mode = 0, int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL); + + CFX_DIBitmap* GetBackDrop(); + + FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, int left, int top, int blend_type = FXDIB_BLEND_NORMAL, + void* pIccTransform = NULL); + + FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, + FX_DWORD flags = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL StretchBitMask(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, + FX_DWORD color, FX_DWORD flags = 0, int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, + const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause); + + void CancelDIBits(FX_LPVOID handle); + + FX_BOOL DrawNormalText(int nChars, const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, CFX_FontCache* pCache, + FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device, + FX_DWORD fill_color, FX_DWORD text_flags, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL DrawTextPath(int nChars, const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, CFX_FontCache* pCache, + FX_FLOAT font_size, const CFX_AffineMatrix* pText2User, + const CFX_AffineMatrix* pUser2Device, const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, FX_DWORD stroke_color, CFX_PathData* pClippingPath, int nFlag = 0, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); + virtual void Begin() {} + virtual void End() {} +private: + + CFX_DIBitmap* m_pBitmap; + + + + int m_Width; + + int m_Height; + + int m_bpp; + + int m_RenderCaps; + + int m_DeviceClass; + + FX_RECT m_ClipBox; + +protected: + + IFX_RenderDeviceDriver* m_pDeviceDriver; +private: + + void InitDeviceInfo(); + + void UpdateClipBox(); +}; +class CFX_FxgeDevice : public CFX_RenderDevice +{ +public: + + CFX_FxgeDevice(); + + ~CFX_FxgeDevice(); + + FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); + + FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); +protected: + + FX_BOOL m_bOwnedBitmap; +}; +class CFX_SkiaDevice : public CFX_RenderDevice +{ +public: + + CFX_SkiaDevice(); + + ~CFX_SkiaDevice(); + + FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); + + FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); +protected: + + FX_BOOL m_bOwnedBitmap; +}; +class IFX_RenderDeviceDriver : public CFX_Object +{ +public: + + static IFX_RenderDeviceDriver* CreateFxgeDriver(CFX_DIBitmap* pBitmap, FX_BOOL bRgbByteOrder = FALSE, + CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); + + virtual ~IFX_RenderDeviceDriver() {} + virtual void Begin() { } + virtual void End() { } + + virtual int GetDeviceCaps(int caps_id) = 0; + + virtual CFX_Matrix GetCTM() const + { + return CFX_Matrix(); + } + + virtual FX_BOOL IsPSPrintDriver() + { + return FALSE; + } + + virtual FX_BOOL StartRendering() + { + return TRUE; + } + + virtual void EndRendering() {} + + + + + virtual void SaveState() = 0; + + virtual void RestoreState(FX_BOOL bKeepSaved = FALSE) = 0; + + + virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode + ) = 0; + + virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState + ) + { + return FALSE; + } + + virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL + ) = 0; + + virtual FX_BOOL SetPixel(int x, int y, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL) + { + return FALSE; + } + + virtual FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD fill_color, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) + { + return FALSE; + } + + virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) + { + return FALSE; + } + + virtual FX_BOOL GetClipBox(FX_RECT* pRect) = 0; + + virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL, FX_BOOL bDEdge = FALSE) + { + return FALSE; + } + virtual CFX_DIBitmap* GetBackDrop() + { + return NULL; + } + + virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, + int dest_left, int dest_top, int blend_type, + int alpha_flag = 0, void* pIccTransform = NULL) = 0; + + virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, + int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; + + virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, + const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle, + int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; + + virtual FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) + { + return FALSE; + } + + virtual void CancelDIBits(FX_LPVOID handle) {} + + virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, + CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL) + { + return FALSE; + } + + virtual void* GetPlatformSurface() + { + return NULL; + } + + virtual int GetDriverType() + { + return 0; + } + + virtual void ClearDriver() {} +}; +class IFX_PSOutput +{ +public: + + virtual void OutputPS(FX_LPCSTR string, int len) = 0; + virtual void Release() = 0; +}; +class CPSFont; +class CFX_PSRenderer : public CFX_Object +{ +public: + + CFX_PSRenderer(); + + ~CFX_PSRenderer(); + + void Init(IFX_PSOutput* pOutput, int ps_level, int width, int height, FX_BOOL bCmykOutput); + FX_BOOL StartRendering(); + void EndRendering(); + + void SaveState(); + + void RestoreState(FX_BOOL bKeepSaved = FALSE); + + void SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode + ); + + void SetClip_PathStroke(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState + ); + + FX_RECT GetClipBox() + { + return m_ClipBox; + } + + FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL + ); + + FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, + int dest_width, int dest_height, FX_DWORD flags, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL DrawDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, + const CFX_AffineMatrix* pMatrix, FX_DWORD flags, + int alpha_flag = 0, void* pIccTransform = NULL); + + FX_BOOL DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, CFX_FontCache* pCache, + const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, + int alpha_flag = 0, void* pIccTransform = NULL); +private: + + IFX_PSOutput* m_pOutput; + + int m_PSLevel; + + CFX_GraphStateData m_CurGraphState; + + FX_BOOL m_bGraphStateSet; + + FX_BOOL m_bCmykOutput; + + FX_BOOL m_bColorSet; + + FX_DWORD m_LastColor; + + FX_RECT m_ClipBox; + + CFX_ArrayTemplate m_PSFontList; + + CFX_ArrayTemplate m_ClipBoxStack; + FX_BOOL m_bInited; + + void OutputPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device); + + void SetGraphState(const CFX_GraphStateData* pGraphState); + + void SetColor(FX_DWORD color, int alpha_flag, void* pIccTransform); + + void FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont, const FXTEXT_CHARPOS& charpos, int& ps_fontnum, int &ps_glyphindex); + + void WritePSBinary(FX_LPCBYTE data, int len); +}; +#endif diff --git a/core/include/fxge/fx_ge_apple.h b/core/include/fxge/fx_ge_apple.h index f13a1b38be..44bf2a028a 100644 --- a/core/include/fxge/fx_ge_apple.h +++ b/core/include/fxge/fx_ge_apple.h @@ -1,26 +1,26 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _FX_GE_APPLE_H_ -#define _FX_GE_APPLE_H_ -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ -class CFX_QuartzDevice : public CFX_RenderDevice -{ -public: - CFX_QuartzDevice(); - ~CFX_QuartzDevice(); - FX_BOOL Attach(CGContextRef context, FX_INT32 nDeviceClass = FXDC_DISPLAY); - FX_BOOL Attach(CFX_DIBitmap* pBitmap); - FX_BOOL Create(FX_INT32 width, FX_INT32 height, FXDIB_Format format); - - CGContextRef GetContext(); - -protected: - CGContextRef m_pContext; - FX_BOOL m_bOwnedBitmap; -}; -#endif -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FX_GE_APPLE_H_ +#define _FX_GE_APPLE_H_ +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ +class CFX_QuartzDevice : public CFX_RenderDevice +{ +public: + CFX_QuartzDevice(); + ~CFX_QuartzDevice(); + FX_BOOL Attach(CGContextRef context, FX_INT32 nDeviceClass = FXDC_DISPLAY); + FX_BOOL Attach(CFX_DIBitmap* pBitmap); + FX_BOOL Create(FX_INT32 width, FX_INT32 height, FXDIB_Format format); + + CGContextRef GetContext(); + +protected: + CGContextRef m_pContext; + FX_BOOL m_bOwnedBitmap; +}; +#endif +#endif diff --git a/core/include/fxge/fx_ge_win32.h b/core/include/fxge/fx_ge_win32.h index 0b421db788..311d355ef7 100644 --- a/core/include/fxge/fx_ge_win32.h +++ b/core/include/fxge/fx_ge_win32.h @@ -1,105 +1,105 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _FX_GE_WIN32_H_ -#define _FX_GE_WIN32_H_ -#ifdef _WIN32 -#ifndef _WINDOWS_ -#include -#endif -#define WINDIB_OPEN_MEMORY 0x1 -#define WINDIB_OPEN_PATHNAME 0x2 -typedef struct WINDIB_Open_Args_ { - - int flags; - - const FX_BYTE* memory_base; - - size_t memory_size; - - FX_LPCWSTR path_name; -} WINDIB_Open_Args_; -class CFX_WindowsDIB : public CFX_DIBitmap -{ -public: - - static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap); - - static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData); - - static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC); - - static CFX_DIBitmap* LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pPalette = NULL, FX_DWORD size = 256); - - static CFX_DIBitmap* LoadFromFile(FX_LPCWSTR filename); - - static CFX_DIBitmap* LoadFromFile(FX_LPCSTR filename) - { - return LoadFromFile(CFX_WideString::FromLocal(filename)); - } - - static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); - - CFX_WindowsDIB(HDC hDC, int width, int height); - - ~CFX_WindowsDIB(); - - HDC GetDC() const - { - return m_hMemDC; - } - - HBITMAP GetWindowsBitmap() const - { - return m_hBitmap; - } - - void LoadFromDevice(HDC hDC, int left, int top); - - void SetToDevice(HDC hDC, int left, int top); -protected: - - HDC m_hMemDC; - - HBITMAP m_hBitmap; - - HBITMAP m_hOldBitmap; -}; -class CFX_WindowsDevice : public CFX_RenderDevice -{ -public: - static IFX_RenderDeviceDriver* CreateDriver(HDC hDC, FX_BOOL bCmykOutput = FALSE); - - CFX_WindowsDevice(HDC hDC, FX_BOOL bCmykOutput = FALSE, FX_BOOL bForcePSOutput = FALSE, int psLevel = 2); - - HDC GetDC() const; - - FX_BOOL m_bForcePSOutput; - - static int m_psLevel; -}; -class CFX_WinBitmapDevice : public CFX_RenderDevice -{ -public: - - CFX_WinBitmapDevice(int width, int height, FXDIB_Format format); - - ~CFX_WinBitmapDevice(); - - HDC GetDC() - { - return m_hDC; - } -protected: - - HBITMAP m_hBitmap; - - HBITMAP m_hOldBitmap; - - HDC m_hDC; -}; -#endif -#endif +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef _FX_GE_WIN32_H_ +#define _FX_GE_WIN32_H_ +#ifdef _WIN32 +#ifndef _WINDOWS_ +#include +#endif +#define WINDIB_OPEN_MEMORY 0x1 +#define WINDIB_OPEN_PATHNAME 0x2 +typedef struct WINDIB_Open_Args_ { + + int flags; + + const FX_BYTE* memory_base; + + size_t memory_size; + + FX_LPCWSTR path_name; +} WINDIB_Open_Args_; +class CFX_WindowsDIB : public CFX_DIBitmap +{ +public: + + static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap); + + static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData); + + static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC); + + static CFX_DIBitmap* LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pPalette = NULL, FX_DWORD size = 256); + + static CFX_DIBitmap* LoadFromFile(FX_LPCWSTR filename); + + static CFX_DIBitmap* LoadFromFile(FX_LPCSTR filename) + { + return LoadFromFile(CFX_WideString::FromLocal(filename)); + } + + static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); + + CFX_WindowsDIB(HDC hDC, int width, int height); + + ~CFX_WindowsDIB(); + + HDC GetDC() const + { + return m_hMemDC; + } + + HBITMAP GetWindowsBitmap() const + { + return m_hBitmap; + } + + void LoadFromDevice(HDC hDC, int left, int top); + + void SetToDevice(HDC hDC, int left, int top); +protected: + + HDC m_hMemDC; + + HBITMAP m_hBitmap; + + HBITMAP m_hOldBitmap; +}; +class CFX_WindowsDevice : public CFX_RenderDevice +{ +public: + static IFX_RenderDeviceDriver* CreateDriver(HDC hDC, FX_BOOL bCmykOutput = FALSE); + + CFX_WindowsDevice(HDC hDC, FX_BOOL bCmykOutput = FALSE, FX_BOOL bForcePSOutput = FALSE, int psLevel = 2); + + HDC GetDC() const; + + FX_BOOL m_bForcePSOutput; + + static int m_psLevel; +}; +class CFX_WinBitmapDevice : public CFX_RenderDevice +{ +public: + + CFX_WinBitmapDevice(int width, int height, FXDIB_Format format); + + ~CFX_WinBitmapDevice(); + + HDC GetDC() + { + return m_hDC; + } +protected: + + HBITMAP m_hBitmap; + + HBITMAP m_hOldBitmap; + + HDC m_hDC; +}; +#endif +#endif -- cgit v1.2.3