1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/sgdi/ShaperCli.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,166 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Contains client-side shaper functionality.
1.18 +//
1.19 +//
1.20 +
1.21 +#include "ShapeImpl.h"
1.22 +#include "ShapeInfo.h"
1.23 +#include <gdi.h>
1.24 +#include "GDIPANIC.h"
1.25 +
1.26 +GLREF_C void Panic(TInt aError);
1.27 +
1.28 +/** Construct an RShapeInfo. */
1.29 +/** @internalComponent */
1.30 +EXPORT_C RShapeInfo::RShapeInfo()
1.31 + : iFont(0), iHeader(0), iEndOfShapedText(-1), iContextualProcessFunc(0) {}
1.32 +
1.33 +/** Perform shaping on the text in aText between aStartOfTextToShape and
1.34 +aEndOfTextToShape, based on the script conventions implied by aScriptCode.
1.35 +@param aFont The font to use for the shaping.
1.36 +@param aText The text, including context.
1.37 +@param aStartOfTextToShape
1.38 + The start position within aText of the text to be shaped.
1.39 +@param aEndOfTextToShape
1.40 + The end position within aText of the text to be shaped.
1.41 +@param aScriptCode The script code for the script being shaped.
1.42 +@param aLanguageCode The language code for the language being shaped.
1.43 +@return
1.44 + KErrNone if the text was successfully shaped, KErrNotSupported if aFont has
1.45 + no shaper, KErrCouldNotConnect if the font bitmap server has not been
1.46 + started.
1.47 +*/
1.48 +TInt RShapeInfo::Open(const CFont* aFont, const TDesC& aText,
1.49 + TInt aStartOfTextToShape, TInt aEndOfTextToShape,
1.50 + TInt aScriptCode, TInt aLanguageCode)
1.51 + {
1.52 + GDI_ASSERT_DEBUG(0 <= aStartOfTextToShape,
1.53 + EGdiPanic_InvalidInputParam);
1.54 + GDI_ASSERT_DEBUG(aStartOfTextToShape <= aEndOfTextToShape,
1.55 + EGdiPanic_InvalidInputParam);
1.56 + GDI_ASSERT_DEBUG(aEndOfTextToShape <= aText.Length(),
1.57 + EGdiPanic_InvalidInputParam);
1.58 + iFont = aFont;
1.59 + TFontShapeFunctionParameters param;
1.60 + param.iText = &aText;
1.61 + param.iStart = aStartOfTextToShape;
1.62 + param.iEnd = aEndOfTextToShape;
1.63 + param.iScript = aScriptCode;
1.64 + param.iLanguage = aLanguageCode;
1.65 + const TInt r = aFont->ExtendedFunction(KFontGetShaping, ¶m);
1.66 + iHeader = r == KErrNone ? param.iShapeHeaderOutput : 0;
1.67 + if(iHeader)
1.68 + iEndOfShapedText = aEndOfTextToShape;
1.69 + return r;
1.70 + }
1.71 +
1.72 +/** Frees the memory associated with this shaping information. */
1.73 +/** @internalComponent */
1.74 +EXPORT_C void RShapeInfo::Close()
1.75 + {
1.76 + if (iHeader)
1.77 + {
1.78 + TFontShapeDeleteFunctionParameters param;
1.79 + param.iShapeHeader = iHeader;
1.80 + iFont->ExtendedFunction(KFontDeleteShaping, ¶m);
1.81 + iHeader = NULL;
1.82 + iEndOfShapedText = -1;
1.83 + // We don't reset iSingleContextChar because we want the context to remain throughout,
1.84 + // even when the session is closed. It would eventually simply go out of scope.
1.85 + }
1.86 + }
1.87 +
1.88 +/** Returns the number of glyphs in the shaped output.
1.89 +@return The number of glyphs. Also equal to the size of the Glyphs() array and
1.90 +the GlyphPositions() array. */
1.91 +TInt RShapeInfo::GlyphCount() const
1.92 + {
1.93 + GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
1.94 + return iHeader->iGlyphCount;
1.95 + }
1.96 +
1.97 +/** Returns the array of glyphs. These must be ORed with 0x80000000 to make
1.98 +glyph numbers that functions like CFbsFont::Rasterize can accept to avoid
1.99 +confusing glyph numbers with Unicode character numbers.
1.100 +@return The glyph array. The size of this array is RShapeInfo::GlyphCount
1.101 +@see GlyphCount */
1.102 +const TInt32* RShapeInfo::Glyphs() const
1.103 + {
1.104 + GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
1.105 + return reinterpret_cast<const TInt32*>(iHeader->iBuffer);
1.106 + }
1.107 +
1.108 +/** Returns the array of positions for the glyphs returned by Glyphs, and the
1.109 +total advance for the text.
1.110 +@return
1.111 + Array of glyph positions in pixels, relative to the pen position before
1.112 + the glyphs are drawn. The array has GlyphCount() + 1 entries, as the
1.113 + last entry represents the total advance of the text. */
1.114 +const RShapeInfo::TPoint16* RShapeInfo::GlyphPositions() const
1.115 + {
1.116 + GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
1.117 + return reinterpret_cast<const RShapeInfo::TPoint16*>(iHeader->iBuffer
1.118 + + ((iHeader->iGlyphCount) << 2));
1.119 + }
1.120 +
1.121 +/** Returns the pen advance these glyphs require.
1.122 +@return The pen advance; where to move the pen after drawing all the glyphs. */
1.123 +RShapeInfo::TPoint16 RShapeInfo::Advance() const
1.124 + {
1.125 + GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
1.126 + RShapeInfo::TPoint16 r;
1.127 + r.iX = *reinterpret_cast<const TInt16*>(iHeader->iBuffer
1.128 + + (iHeader->iGlyphCount << 3));
1.129 + r.iY = *reinterpret_cast<const TInt16*>(iHeader->iBuffer
1.130 + + (iHeader->iGlyphCount << 3) + 2);
1.131 + return r;
1.132 + }
1.133 +
1.134 +/** Returns the array of indices.
1.135 +@return
1.136 + Indices[n] is the position in the input text that produced Glyphs[n].
1.137 +*/
1.138 +const TInt16* RShapeInfo::Indices() const
1.139 + {
1.140 + GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
1.141 + return reinterpret_cast<const TInt16*>(iHeader->iBuffer
1.142 + + (iHeader->iGlyphCount << 3) + 4);
1.143 + }
1.144 +
1.145 +TInt RShapeInfo::EndOfShapedText()
1.146 + {
1.147 + return iEndOfShapedText;
1.148 + }
1.149 +
1.150 +/** Checks if this shaping information is still occupying memory. */
1.151 +EXPORT_C TBool RShapeInfo::IsOpen()
1.152 + {
1.153 + if(iHeader && iHeader->iGlyphCount >= 0 && iHeader->iCharacterCount >=0)
1.154 + return ETrue;
1.155 + else
1.156 + return EFalse;
1.157 +
1.158 + }
1.159 +
1.160 +void RShapeInfo::SetContext(TAny* aContextualProcessFunc)
1.161 + {
1.162 + iContextualProcessFunc = aContextualProcessFunc;
1.163 + }
1.164 +
1.165 +TAny* RShapeInfo::GetContext()
1.166 + {
1.167 + return iContextualProcessFunc;
1.168 + }
1.169 +