os/graphics/graphicsdeviceinterface/gdi/sgdi/ShaperCli.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Contains client-side shaper functionality.
    15 // 
    16 //
    17 
    18 #include "ShapeImpl.h"
    19 #include "ShapeInfo.h"
    20 #include <gdi.h>
    21 #include "GDIPANIC.h"
    22 
    23 GLREF_C void Panic(TInt aError);
    24 
    25 /** Construct an RShapeInfo. */
    26 /** @internalComponent */
    27 EXPORT_C RShapeInfo::RShapeInfo()
    28 	: iFont(0), iHeader(0), iEndOfShapedText(-1), iContextualProcessFunc(0) {}
    29 
    30 /** Perform shaping on the text in aText between aStartOfTextToShape and
    31 aEndOfTextToShape, based on the script conventions implied by aScriptCode.
    32 @param aFont The font to use for the shaping.
    33 @param aText The text, including context.
    34 @param aStartOfTextToShape
    35 	The start position within aText of the text to be shaped.
    36 @param aEndOfTextToShape
    37 	The end position within aText of the text to be shaped.
    38 @param aScriptCode The script code for the script being shaped.
    39 @param aLanguageCode The language code for the language being shaped.
    40 @return
    41 	KErrNone if the text was successfully shaped, KErrNotSupported if aFont has
    42 	no shaper, KErrCouldNotConnect if the font bitmap server has not been
    43 	started.
    44 */
    45 TInt RShapeInfo::Open(const CFont* aFont, const TDesC& aText,
    46 	TInt aStartOfTextToShape, TInt aEndOfTextToShape,
    47 	TInt aScriptCode, TInt aLanguageCode)
    48 	{
    49 	GDI_ASSERT_DEBUG(0 <= aStartOfTextToShape,
    50 		EGdiPanic_InvalidInputParam);
    51 	GDI_ASSERT_DEBUG(aStartOfTextToShape <= aEndOfTextToShape,
    52 		EGdiPanic_InvalidInputParam);
    53 	GDI_ASSERT_DEBUG(aEndOfTextToShape <= aText.Length(),
    54 		EGdiPanic_InvalidInputParam);
    55 	iFont = aFont;
    56 	TFontShapeFunctionParameters param;
    57 	param.iText = &aText;
    58 	param.iStart = aStartOfTextToShape;
    59 	param.iEnd = aEndOfTextToShape;
    60 	param.iScript = aScriptCode;
    61 	param.iLanguage = aLanguageCode;
    62 	const TInt r = aFont->ExtendedFunction(KFontGetShaping, &param);
    63 	iHeader = r == KErrNone ? param.iShapeHeaderOutput : 0;
    64 	if(iHeader)
    65 		iEndOfShapedText = aEndOfTextToShape;
    66 	return r;
    67 	}
    68 
    69 /** Frees the memory associated with this shaping information. */
    70 /** @internalComponent */
    71 EXPORT_C void RShapeInfo::Close()
    72 	{
    73 	if (iHeader)
    74 		{
    75 		TFontShapeDeleteFunctionParameters param;
    76 		param.iShapeHeader = iHeader;
    77 		iFont->ExtendedFunction(KFontDeleteShaping, &param);
    78 		iHeader = NULL;
    79 		iEndOfShapedText = -1;
    80 		// We don't reset iSingleContextChar because we want the context to remain throughout,
    81 		// even when the session is closed. It would eventually simply go out of scope.
    82 		}
    83 	}
    84 
    85 /** Returns the number of glyphs in the shaped output.
    86 @return The number of glyphs. Also equal to the size of the Glyphs() array and
    87 the GlyphPositions() array. */
    88 TInt RShapeInfo::GlyphCount() const
    89 	{
    90 	GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
    91 	return iHeader->iGlyphCount;
    92 	}
    93 
    94 /** Returns the array of glyphs. These must be ORed with 0x80000000 to make
    95 glyph numbers that functions like CFbsFont::Rasterize can accept to avoid
    96 confusing glyph numbers with Unicode character numbers.
    97 @return The glyph array. The size of this array is RShapeInfo::GlyphCount
    98 @see GlyphCount */
    99 const TInt32* RShapeInfo::Glyphs() const
   100 	{
   101 	GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
   102 	return reinterpret_cast<const TInt32*>(iHeader->iBuffer);
   103 	}
   104 
   105 /** Returns the array of positions for the glyphs returned by Glyphs, and the
   106 total advance for the text.
   107 @return
   108 	Array of glyph positions in pixels, relative to the pen position before
   109 	the glyphs are drawn. The array has GlyphCount() + 1 entries, as the
   110 	last entry represents the total advance of the text. */
   111 const RShapeInfo::TPoint16* RShapeInfo::GlyphPositions() const
   112 	{
   113 	GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
   114 	return reinterpret_cast<const RShapeInfo::TPoint16*>(iHeader->iBuffer
   115 		+ ((iHeader->iGlyphCount) << 2));
   116 	}
   117 
   118 /** Returns the pen advance these glyphs require.
   119 @return The pen advance; where to move the pen after drawing all the glyphs. */
   120 RShapeInfo::TPoint16 RShapeInfo::Advance() const
   121 	{
   122 	GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
   123 	RShapeInfo::TPoint16 r;
   124 	r.iX = *reinterpret_cast<const TInt16*>(iHeader->iBuffer
   125 		+ (iHeader->iGlyphCount << 3));
   126 	r.iY = *reinterpret_cast<const TInt16*>(iHeader->iBuffer
   127 		+ (iHeader->iGlyphCount << 3) + 2);
   128 	return r;
   129 	}
   130 
   131 /** Returns the array of indices.
   132 @return
   133 	Indices[n] is the position in the input text that produced Glyphs[n].
   134 */
   135 const TInt16* RShapeInfo::Indices() const
   136 	{
   137 	GDI_ASSERT_ALWAYS(iHeader, EGdiPanic_Invariant);
   138 	return reinterpret_cast<const TInt16*>(iHeader->iBuffer
   139 		+ (iHeader->iGlyphCount << 3) + 4);
   140 	}
   141 	
   142 TInt RShapeInfo::EndOfShapedText()
   143 	{
   144 	return iEndOfShapedText;
   145 	}
   146 
   147 /** Checks if this shaping information is still occupying memory. */
   148 EXPORT_C TBool RShapeInfo::IsOpen()
   149 	{
   150 	if(iHeader && iHeader->iGlyphCount >= 0 && iHeader->iCharacterCount >=0)
   151 		return ETrue;
   152 	else
   153 		return EFalse;
   154 		
   155 	}
   156 
   157 void RShapeInfo::SetContext(TAny* aContextualProcessFunc)
   158 	{
   159 	iContextualProcessFunc = aContextualProcessFunc;
   160 	}
   161 	
   162 TAny* RShapeInfo::GetContext()
   163 	{
   164 	return iContextualProcessFunc;
   165 	}
   166