Back to index

lightning-sunbird  0.9+nobinonly
nsUnicodeRenderingToolkit.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsUnicodeRenderingToolkit_h__
00039 #define nsUnicodeRenderingToolkit_h__
00040 
00041 #include <UnicodeConverter.h>
00042 
00043 #include "nsATSUIUtils.h"
00044 
00045 #include "nsCOMPtr.h"
00046 #include "nsISaveAsCharset.h"
00047 #include "nsIRenderingContext.h"
00048 
00049 class nsUnicodeFallbackCache;
00050 class nsIDeviceContext;
00051 class nsGraphicState;
00052 class nsUnicodeFontMappingMac;
00053 
00054 class nsUnicodeRenderingToolkit 
00055 {
00056 public:
00057   nsUnicodeRenderingToolkit() {};
00058   virtual ~nsUnicodeRenderingToolkit() {};
00059 
00060   nsresult PrepareToDraw(float aP2T, nsIDeviceContext* aContext, nsGraphicState* aGS, 
00061                          CGrafPtr aPort, PRBool aRightToLeftText);
00062   nsresult GetTextDimensions(const PRUnichar *aString, PRUint32 aLength, 
00063                              nsTextDimensions &aDimension, PRInt32 *aFontID);
00064   nsresult GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
00065                     PRInt32 *aFontID);
00066 
00067   nsresult DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY,
00068                       PRInt32 aFontID,
00069                       const nscoord* aSpacing);
00070 #ifdef MOZ_MATHML
00071   nsresult GetTextBoundingMetrics(const PRUnichar *aString, PRUint32 aLength,
00072                                   nsBoundingMetrics &aBoundingMetrics, PRInt32 *aFontID);
00073 #endif // MOZ_MATHML
00074 
00075 private:  
00076   // Unicode text measure/drawing functions
00077   PRBool TECFallbackGetDimensions(const PRUnichar *pChar, nsTextDimensions& oWidth,
00078                                   short fontNum, nsUnicodeFontMappingMac& fontMapping);
00079   PRBool TECFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth,
00080                              short fontNum, nsUnicodeFontMappingMac& fontMapping);
00081                   
00082   PRBool ATSUIFallbackGetDimensions(const PRUnichar *pChar, nsTextDimensions& oWidth, short fontNum,  
00083                                     short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00084   PRBool ATSUIFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth, short fontNum, 
00085                                short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00086   PRBool SurrogateGetDimensions(const PRUnichar *aSurrogatePt, nsTextDimensions& oWidth, short fontNum,  
00087                                     short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00088   PRBool SurrogateDrawChar(const PRUnichar *aSurrogatePt, PRInt32 x, PRInt32 y, short& oWidth, short fontNum, 
00089                                short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00090   
00091   PRBool UPlusFallbackGetWidth(const PRUnichar *pChar, short& oWidth);
00092   PRBool UPlusFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth);
00093 
00094   PRBool QuestionMarkFallbackGetWidth(const PRUnichar *pChar, short& oWidth);
00095   PRBool QuestionMarkFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth);
00096 
00097   PRBool LatinFallbackGetWidth(const PRUnichar *pChar, short& oWidth);
00098   PRBool LatinFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth);
00099   PRBool PrecomposeHangulFallbackGetWidth(const PRUnichar *pChar, short& oWidth,short koreanFont, short origFont);
00100   PRBool PrecomposeHangulFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth,
00101                                           short koreanFont, short origFont);
00102   PRBool TransliterateFallbackGetWidth(const PRUnichar *pChar, short& oWidth);
00103   PRBool TransliterateFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth);
00104   PRBool LoadTransliterator();
00105   
00106   void GetScriptTextWidth(const char* aText, ByteCount aLen, short& aWidth);
00107   void DrawScriptText(const char* aText, ByteCount aLen, PRInt32 x, PRInt32 y, short& aWidth);
00108   
00109   nsresult GetTextSegmentWidth(const PRUnichar *aString, PRUint32 aLength, short fontNum, 
00110                                nsUnicodeFontMappingMac& fontMapping, PRUint32& oWidth);
00111   nsresult GetTextSegmentDimensions(const PRUnichar *aString, PRUint32 aLength, short fontNum, 
00112                                     nsUnicodeFontMappingMac& fontMapping, nsTextDimensions& aDimension);
00113   nsresult DrawTextSegment(const PRUnichar *aString, PRUint32 aLength, short fontNum, 
00114                            nsUnicodeFontMappingMac& fontMapping, PRInt32 x, PRInt32 y, PRUint32& oWidth);
00115 
00116 #ifdef MOZ_MATHML
00117   PRBool TECFallbackGetBoundingMetrics(const PRUnichar *pChar, nsBoundingMetrics& oBoundingMetrics,
00118                                                                       short fontNum, nsUnicodeFontMappingMac& fontMapping);
00119   PRBool ATSUIFallbackGetBoundingMetrics(const PRUnichar *pChar, nsBoundingMetrics& oBoundingMetrics, short fontNum,
00120                                          short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00121   PRBool SurrogateGetBoundingMetrics(const PRUnichar *aSurrogatePt, nsBoundingMetrics& oBoundingMetrics, short fontNum,
00122                                          short aSize, PRBool aBold, PRBool aItalic, nscolor aColor);
00123   void GetScriptTextBoundingMetrics(const char* aText, ByteCount aLen, ScriptCode aScript, nsBoundingMetrics& oBoundingMetrics);
00124   nsresult GetTextSegmentBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, short fontNum,
00125                                          nsUnicodeFontMappingMac& fontMapping, nsBoundingMetrics& oBoundingMetrics);
00126 #endif // MOZ_MATHML
00127 
00128   nsUnicodeFallbackCache* GetTECFallbackCache();    
00129 private:
00130   float mP2T; // Pixel to Twip conversion factor
00131   nsIDeviceContext *mContext;
00132   nsGraphicState *mGS; // current graphic state - shortcut for mCurrentSurface->GetGS()
00133 
00134   CGrafPtr mPort; // current grafPort - shortcut for mCurrentSurface->GetPort()
00135   nsATSUIToolkit mATSUIToolkit;
00136   nsCOMPtr<nsISaveAsCharset> mTrans;
00137   PRBool mRightToLeftText;
00138 
00139 };
00140 #endif /* nsUnicodeRenderingToolkit_h__ */