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