1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textbase/sgdi/FONT.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1812 @@
1.4 +// Copyright (c) 1998-2010 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 +//
1.18 +
1.19 +//#include <textbase.h>
1.20 +#include <openfont.h>
1.21 +#include "GlyphSel.h"
1.22 +#include "FontThai.h"
1.23 +#include "FontArabic.h"
1.24 +#include "FontIndic.h"
1.25 +#include "TextBasePanic.h"
1.26 +#include "glyphsample.h"
1.27 +#include "gdiinline.inl"
1.28 +//#include "gdistructs.h"
1.29 +//#include "gdiconsts.h"
1.30 +#include <graphics/gdi/gdistructs.h>
1.31 +#include <graphics/gdi/gdiconsts.h>
1.32 +#include "gdiplatapi.h"
1.33 +
1.34 +/**
1.35 + Names holds the types & data associated with the glyph selection
1.36 + algorithm in CFont::GetCharacterPosition().
1.37 +@internalComponent
1.38 +*/
1.39 +namespace GlyphSelection
1.40 + {
1.41 +
1.42 + typedef TBool (*ProcessFunc)(TGlyphSelectionState& aGss, RShapeInfo&);
1.43 +
1.44 + /**
1.45 + This structure defines the fields present in each row of the GlyphTable
1.46 + datat table below.
1.47 + @internalComponent
1.48 + */
1.49 + struct TTableEntry
1.50 + {
1.51 + TUint iLow;
1.52 + TUint iHigh;
1.53 + ProcessFunc iProcessFunc;
1.54 + };
1.55 +
1.56 + /**
1.57 + This table encodes the Unicode character ranges and the glyph selector
1.58 + classes to be used for each character range when processing characters
1.59 + into glyph clusters in CFont::GetCharacterPosition().
1.60 + New glyph selection classes must make sure they are listed in this
1.61 + table to ensure they are invoked as required.
1.62 + A '0' iProcessFunc entry tells the algorithm to skip the character.
1.63 + @internalComponent
1.64 + */
1.65 + static const TTableEntry Table[] =
1.66 + {
1.67 + // iLow, iHigh, iProcessFunc
1.68 + { 0x0000, 0x00AC, GlyphSelector_Default::Process},
1.69 + { 0x00AD, 0x00AD, GlyphSelector_SoftHyphen::Process},
1.70 + { 0x00AE, 0x05FF, GlyphSelector_Default::Process},
1.71 + { 0x0600, 0x06FF, GlyphSelector_Arabic::Process},
1.72 + { 0x0700, 0x08FF, GlyphSelector_Default::Process},
1.73 + { 0x0900, 0x0970, GlyphSelector_Devanagari::Process},
1.74 + { 0x0980, 0x09FF, GlyphSelector_Bengali::Process},
1.75 + { 0x0A00, 0x0A7F, GlyphSelector_Gurmukhi::Process},
1.76 + { 0x0A80, 0x0AFF, GlyphSelector_Gujarati::Process},
1.77 + { 0x0B80, 0x0BFF, GlyphSelector_Tamil::Process},
1.78 + { 0x0C00, 0x0C7F, GlyphSelector_Telugu::Process},
1.79 + { 0x0C80, 0x0CFF, GlyphSelector_Kannada::Process},
1.80 + { 0x0D00, 0x0D7F, GlyphSelector_Malayalam::Process},
1.81 + { 0x0D80, 0x0DFF, GlyphSelector_Default::Process},
1.82 + { 0x0E00, 0x0E32, GlyphSelector_Thai::Process},
1.83 + { 0x0E33, 0x0E33, GlyphSelector_ThaiSaraAm::Process},
1.84 + { 0x0E34, 0x0E7F, GlyphSelector_Thai::Process},
1.85 + { 0x0E80, 0x200B, GlyphSelector_Default::Process},
1.86 + { 0x200C, 0x200F, 0},
1.87 + { 0x2010, 0x2029, GlyphSelector_Default::Process},
1.88 + { 0x202A, 0x202E, 0},
1.89 + { 0x202F, 0xFFFD, GlyphSelector_Default::Process},
1.90 + { 0xFFFE, 0xFFFF, 0},
1.91 + { 0x10000, 0x10FFFF, GlyphSelector_Default::Process},
1.92 + {0xFFFFFFFF,0xFFFFFFFF, 0}
1.93 + };
1.94 + }
1.95 +
1.96 +/** Find appropriate processor function for the given character.
1.97 +@param aChar Character for processing.
1.98 +@return processor function or 0 if the character is to be skipped.
1.99 +@internalComponent */
1.100 +GlyphSelection::ProcessFunc CharacterToProcessFunction(TInt aChar)
1.101 + {
1.102 + for (const GlyphSelection::TTableEntry* glyphSel = GlyphSelection::Table;
1.103 + glyphSel->iLow != 0xFFFFFFFF; glyphSel++)
1.104 + {
1.105 + if ((glyphSel->iLow <= aChar) && (aChar <= glyphSel->iHigh))
1.106 + return glyphSel->iProcessFunc;
1.107 + }
1.108 + return 0;
1.109 + }
1.110 +
1.111 +/**
1.112 +@internalTechnology For use by TFontStyle/TOpenFontSpec.
1.113 +*/
1.114 +EXPORT_C TBool FontEffect::IsEffectOn(TEffect aEffect, TUint32 aFontEffect)
1.115 + {
1.116 + return aEffect & aFontEffect;
1.117 + }
1.118 +
1.119 +/**
1.120 +@internalTechnology For use by TFontStyle/TOpenFontSpec.
1.121 +*/
1.122 +EXPORT_C void FontEffect::SetEffect(TEffect aEffect, TBool aOn, TUint32& aFontEffect)
1.123 + {
1.124 + if (aOn)
1.125 + aFontEffect |= aEffect;
1.126 + else
1.127 + aFontEffect &= ~aEffect;
1.128 + }
1.129 +
1.130 +
1.131 +//
1.132 +// TFontStyle
1.133 +//
1.134 +
1.135 +/** Default C++ constructor. */
1.136 +EXPORT_C TFontStyle::TFontStyle():
1.137 + iFlags(0), iReserved1(0), iReserved2(0)
1.138 + {}
1.139 +
1.140 +
1.141 +/** Constructs a TFontStyle object with the specified attributes.
1.142 +@param aPost The posture attribute.
1.143 +@param aStrWgt The stroke weight attribute.
1.144 +@param aPrintPos The print position attribute. */
1.145 +EXPORT_C TFontStyle::TFontStyle(TFontPosture aPostr,TFontStrokeWeight aWgt,TFontPrintPosition aPos):
1.146 + iFlags(0), iReserved1(0), iReserved2(0)
1.147 + {
1.148 + if (aPostr == EPostureItalic)
1.149 + {
1.150 + iFlags |= EItalic;
1.151 + }
1.152 + if (aWgt == EStrokeWeightBold)
1.153 + {
1.154 + iFlags |= EBold;
1.155 + }
1.156 + if (aPos == EPrintPosSuperscript)
1.157 + {
1.158 + iFlags |= ESuper;
1.159 + }
1.160 + else if (aPos == EPrintPosSubscript)
1.161 + {
1.162 + iFlags |= ESub;
1.163 + }
1.164 + }
1.165 +
1.166 +
1.167 +EXPORT_C void TFontStyle::InternalizeL(RReadStream& aStream)
1.168 +/** Internalises a font style from a read stream.
1.169 +
1.170 +The presence of this function means that the standard templated operator>>()
1.171 +(defined in s32strm.h) is available to internalise objects of this class.
1.172 +
1.173 +@param aStream The stream from which the font style is to be internalised
1.174 +@leave KErrNoMemory If there is a problem reading from the stream.
1.175 +If internalisation causes an out of memory error. */
1.176 + {
1.177 + iFlags = aStream.ReadUint32L();
1.178 + }
1.179 +
1.180 +
1.181 +EXPORT_C void TFontStyle::ExternalizeL(RWriteStream& aStream) const
1.182 +/** Externalises the font style to a write stream.
1.183 +
1.184 +The presence of this function means that the standard templated operator<<()
1.185 +(defined in s32strm.h) is available to externalise objects of this class.
1.186 +
1.187 +@param aStream The stream to which the font style is to be externalised.
1.188 +@leave KErrNoMemory This function may leave, if the write action causes the
1.189 +stream's resources to be exhausted. */
1.190 + {
1.191 + aStream.WriteUint32L(iFlags);
1.192 + }
1.193 +
1.194 +
1.195 +EXPORT_C TFontPosture TFontStyle::Posture() const
1.196 +/** Gets the posture attribute.
1.197 +
1.198 +@return The font style's posture. */
1.199 + {
1.200 + if(iFlags&EItalic) return(EPostureItalic);
1.201 + return(EPostureUpright);
1.202 + }
1.203 +
1.204 +
1.205 +EXPORT_C TFontStrokeWeight TFontStyle::StrokeWeight() const
1.206 +/** Gets the stroke weight attribute.
1.207 +
1.208 +@return The font style's stroke weight. */
1.209 + {
1.210 + if(iFlags&EBold) return(EStrokeWeightBold);
1.211 + return(EStrokeWeightNormal);
1.212 + }
1.213 +
1.214 +
1.215 +EXPORT_C TFontPrintPosition TFontStyle::PrintPosition() const
1.216 +/** Gets the print position attribute.
1.217 +
1.218 +@return The font style's print position. */
1.219 + {
1.220 + if((iFlags&ESuper) && !(iFlags&ESub)) return(EPrintPosSuperscript);
1.221 + else if((iFlags&ESub) && !(iFlags&ESuper)) return(EPrintPosSubscript);
1.222 + return(EPrintPosNormal);
1.223 + }
1.224 +
1.225 +
1.226 +EXPORT_C void TFontStyle::SetPosture(TFontPosture aPosture)
1.227 +/** Sets the posture attribute.
1.228 +
1.229 +@param aPosture The posture to be set. */
1.230 + {
1.231 + if(aPosture==EPostureItalic) iFlags|=EItalic;
1.232 + else iFlags&=~EItalic;
1.233 + }
1.234 +
1.235 +
1.236 +EXPORT_C void TFontStyle::SetStrokeWeight(TFontStrokeWeight aStrokeWeight)
1.237 +/** Sets the stroke weight attribute.
1.238 +
1.239 +@param aStrokeWeight The stroke weight to be set. */
1.240 + {
1.241 + if(aStrokeWeight==EStrokeWeightBold) iFlags|=EBold;
1.242 + else iFlags&=~EBold;
1.243 + }
1.244 +
1.245 +
1.246 +EXPORT_C void TFontStyle::SetPrintPosition(TFontPrintPosition aPrintPosition)
1.247 +/** Sets the print position attribute.
1.248 +
1.249 +@param aPrintPosition The print position to be set. */
1.250 + {
1.251 + switch(aPrintPosition)
1.252 + {
1.253 + case EPrintPosSuperscript:
1.254 + {
1.255 + iFlags|=ESuper;
1.256 + iFlags&=~ESub;
1.257 + break;
1.258 + }
1.259 + case EPrintPosSubscript:
1.260 + {
1.261 + iFlags&=~ESuper;
1.262 + iFlags|=ESub;
1.263 + break;
1.264 + }
1.265 + default:
1.266 + {
1.267 + iFlags&=~ESuper;
1.268 + iFlags&=~ESub;
1.269 + }
1.270 + }
1.271 + }
1.272 +
1.273 +/** Gets the font effects flags.
1.274 +@publishedAll
1.275 +@released
1.276 +@return The font effects flags.
1.277 +@see TFontStyle::SetEffects()
1.278 +*/
1.279 +EXPORT_C TUint32 TFontStyle::Effects() const
1.280 + {
1.281 + return 0xFFF0 & iFlags;
1.282 + }
1.283 +
1.284 +/** Checks if a font effect is on.
1.285 +@publishedAll
1.286 +@released
1.287 +@return True represents the specified font effect is on, otherwise off.
1.288 +@param aEffect The font effect to be checked.
1.289 +@see TFontStyle::SetEffects()
1.290 +*/
1.291 +EXPORT_C TBool TFontStyle::IsEffectOn(FontEffect::TEffect aEffect) const
1.292 + {
1.293 + return FontEffect::IsEffectOn(aEffect, iFlags);
1.294 + }
1.295 +
1.296 +/** Sets the font effects flags.
1.297 +@publishedAll
1.298 +@released
1.299 +@param aEffect The font effects flags to be set.
1.300 +@see TFontStyle::Effects()
1.301 +*/
1.302 +EXPORT_C void TFontStyle::SetEffects(TUint32 aEffects)
1.303 + {
1.304 + iFlags &= 0xFFFF000F;
1.305 + iFlags |= 0xFFF0 & aEffects;
1.306 + }
1.307 +
1.308 +/** Sets a font effect to the given state.
1.309 +@publishedAll
1.310 +@released
1.311 +@param aEffect The font effect to be set.
1.312 +@param aOn True represents on, otherwise off.
1.313 +@see TFontStyle::IsEffectOn()
1.314 +*/
1.315 +EXPORT_C void TFontStyle::SetEffects(FontEffect::TEffect aEffect, TBool aOn)
1.316 + {
1.317 + FontEffect::SetEffect(aEffect, aOn, iFlags);
1.318 + }
1.319 +
1.320 +/** Compares a font style for equality.
1.321 +@publishedAll
1.322 +@released
1.323 +@param aFontStyle The font style to be compared with this font style.
1.324 +@return ETrue, if this TFontStyle is equal to aFontStyle, EFalse, otherwise.
1.325 +*/
1.326 +EXPORT_C TBool TFontStyle::operator==(const TFontStyle& aFontStyle) const
1.327 + {
1.328 + return iFlags == aFontStyle.iFlags;
1.329 + }
1.330 +
1.331 +//
1.332 +// TFontSpec
1.333 +//
1.334 +EXPORT_C TFontSpec::TFontSpec():
1.335 + iTypeface(),
1.336 + iHeight(0),
1.337 + iFontStyle()
1.338 +/** Default constructor.
1.339 +
1.340 +The object's font style is set to the default: EPostureUpright, EStrokeWeightNormal,
1.341 +and EPrintPosNormal. */
1.342 + {}
1.343 +
1.344 +
1.345 +EXPORT_C TFontSpec::TFontSpec(const TDesC& aTypefaceName,TInt aHeight):
1.346 + iTypeface(),
1.347 + iHeight(aHeight),
1.348 + iFontStyle(EPostureUpright,EStrokeWeightNormal,EPrintPosNormal)
1.349 +/** Constructs a TFontSpec object with the specified typeface and height.
1.350 +
1.351 +The object's font style is set to the default: EPostureUpright, EStrokeWeightNormal,
1.352 +and EPrintPosNormal.
1.353 +
1.354 +@param aTypefaceName The name of the typeface (e.g. "Roman"). It should be no
1.355 + longer than KMaxTypefaceNameLength characters in length.
1.356 +@param aHeight The height of the typeface, in twips.
1.357 +@panic GDI 6, if aTypefaceName is more than KMaxTypefaceNameLength characters long.
1.358 +*/
1.359 + {
1.360 + iTypeface.SetName(aTypefaceName);
1.361 + }
1.362 +
1.363 +
1.364 +EXPORT_C TBool TFontSpec::operator==(const TFontSpec& aFontSpec) const
1.365 +/** Compares this font specification with another.
1.366 +@param aFontSpec The font specification to be compared with this one.
1.367 +@return ETrue, if the TFontSpecs are identical, EFalse otherwise.
1.368 +*/
1.369 + {
1.370 + return
1.371 + iHeight == aFontSpec.iHeight &&
1.372 + iFontStyle == aFontSpec.iFontStyle &&
1.373 + iTypeface == aFontSpec.iTypeface;
1.374 + }
1.375 +
1.376 +
1.377 +EXPORT_C void TFontSpec::InternalizeL(RReadStream& aStream)
1.378 +/** Internalises a font specification from a read stream.
1.379 +
1.380 +The presence of this function means that the standard templated operator>>()
1.381 +(defined in s32strm.h) is available to internalise objects of this class.
1.382 +
1.383 +@param aStream The stream from which the font specification is to be internalised.
1.384 +@leave KErrNoMemory If internalisation causes an out of memory error. */
1.385 + {
1.386 + iTypeface.InternalizeL(aStream);
1.387 + iHeight=aStream.ReadUint16L();
1.388 + iFontStyle.InternalizeL(aStream);
1.389 + }
1.390 +
1.391 +
1.392 +EXPORT_C void TFontSpec::ExternalizeL(RWriteStream& aStream) const
1.393 +/** Externalises the font specification to a write stream.
1.394 +
1.395 +The presence of this function means that the standard templated operator<<()
1.396 +(defined in s32strm.h) is available to externalise objects of this class.
1.397 +
1.398 +@param aStream The stream to which the font specification is to be externalised
1.399 +
1.400 +@leave KErrNoMemory If the write action causes the stream's resources to be
1.401 +exhausted. */
1.402 + {
1.403 + iTypeface.ExternalizeL(aStream);
1.404 + aStream.WriteUint16L(iHeight);
1.405 + iFontStyle.ExternalizeL(aStream);
1.406 + }
1.407 +
1.408 +EXPORT_C void TFontSpec::SetScriptTypeForMetrics(TLanguage aLanguage)
1.409 +/** Specifies the script with which font metrics calculation will be based on.
1.410 +@param aLanguage The language used to derive the required script.
1.411 +@publishedAll
1.412 +@released
1.413 +*/
1.414 + {
1.415 + iTypeface.SetScriptTypeForMetrics(aLanguage);
1.416 + }
1.417 +
1.418 +EXPORT_C TInt TFontSpec::ScriptTypeForMetrics() const
1.419 +/** Returns the script with which font metrics calculation will be based on.
1.420 +@internalTechnology
1.421 +*/
1.422 + {
1.423 + return iTypeface.ScriptTypeForMetrics();
1.424 + }
1.425 +
1.426 +//
1.427 +// TTypeface
1.428 +//
1.429 +static const TInt KTTypefaceBitsNumAttrib = 3;
1.430 +static const TInt KTTypefaceBitsNumScript = 4;
1.431 +static const TInt KTTypefaceMaskAttrib = (1 << KTTypefaceBitsNumAttrib) - 1;
1.432 +static const TInt KTTypefaceMaskScript = ((1 << KTTypefaceBitsNumScript) - 1) << KTTypefaceBitsNumAttrib;
1.433 +EXPORT_C TTypeface::TTypeface():
1.434 + iName(),
1.435 + iFlags(0)
1.436 +/** Default C++ constructor. */
1.437 + {}
1.438 +
1.439 +/**
1.440 +@internalComponent
1.441 +*/
1.442 +void TTypeface::ResetAttributes()
1.443 + {
1.444 + iFlags &= KTTypefaceMaskScript;
1.445 + }
1.446 +
1.447 +/**
1.448 +@internalComponent
1.449 +*/
1.450 +void TTypeface::ResetScriptType()
1.451 + {
1.452 + iFlags &= KTTypefaceMaskAttrib;
1.453 + }
1.454 +
1.455 +EXPORT_C void TTypeface::InternalizeL(RReadStream& aStream)
1.456 +/** Internalises a typeface from a read stream.
1.457 +
1.458 +The presence of this function means that the standard templated operator>>()
1.459 +(defined in s32strm.h) is available to internalise objects of this class.
1.460 +
1.461 +@param aStream Stream from which the typeface is to be internalised. */
1.462 + {
1.463 + TBuf<KMaxTypefaceNameLength> tempname;
1.464 + aStream >> tempname;
1.465 + new(&iName) TBufC<KMaxTypefaceNameLength>(tempname);
1.466 + iFlags = aStream.ReadInt8L();
1.467 + }
1.468 +
1.469 +
1.470 +EXPORT_C void TTypeface::ExternalizeL(RWriteStream& aStream) const
1.471 +/** Externalises a typeface to a write stream.
1.472 +
1.473 +The presence of this function means that the standard templated operator<<()
1.474 +(defined in s32strm.h) is available to externalise objects of this class.
1.475 +
1.476 +@param aStream The stream to which the typeface is to be externalised. */
1.477 + {
1.478 + aStream << iName;
1.479 + aStream.WriteInt8L(static_cast<TInt8>(iFlags));
1.480 + }
1.481 +
1.482 +
1.483 +EXPORT_C TBool TTypeface::operator==(const TTypeface& aTypeface) const
1.484 +/** Compares two typefaces for equality.
1.485 +
1.486 +@param aTypeface The typeface to be compared with.
1.487 +@return ETrue, if this TTypeface is equal to aTypeface, otherwise EFalse. */
1.488 + {
1.489 + return
1.490 + iFlags == aTypeface.iFlags &&
1.491 + iName == aTypeface.iName;
1.492 + }
1.493 +
1.494 +EXPORT_C void TTypeface::SetAttributes(TInt aAttributes)
1.495 +/** Set the combination of attributes for this typeface.
1.496 +
1.497 +@param aAttributes A bitmap defining the combination of attributes. */
1.498 + {
1.499 + ResetAttributes();
1.500 + iFlags |= KTTypefaceMaskAttrib & aAttributes & (EProportional | ESerif | ESymbol);
1.501 + }
1.502 +
1.503 +
1.504 +EXPORT_C void TTypeface::SetIsProportional(TBool aIsProportional)
1.505 +/** Sets the typeface's proportional attribute.
1.506 +
1.507 +@param aIsProportional ETrue if the typeface is a proportional typeface, otherwise
1.508 +EFalse. */
1.509 + {
1.510 + if (aIsProportional)
1.511 + {
1.512 + iFlags |= EProportional;
1.513 + }
1.514 + else
1.515 + {
1.516 + iFlags &= ~EProportional;
1.517 + }
1.518 + }
1.519 +
1.520 +
1.521 +EXPORT_C void TTypeface::SetIsSerif(TBool aIsSerif)
1.522 +/** Sets the typeface's serif attribute.
1.523 +
1.524 +@param aIsSerif ETrue if the typeface is a serif typeface, otherwise EFalse. */
1.525 + {
1.526 + if (aIsSerif)
1.527 + {
1.528 + iFlags |= ESerif;
1.529 + }
1.530 + else
1.531 + {
1.532 + iFlags &= ~ESerif;
1.533 + }
1.534 + }
1.535 +
1.536 +
1.537 +EXPORT_C void TTypeface::SetIsSymbol(TBool aIsSymbol)
1.538 +/** Sets the typeface's symbol attribute.
1.539 +
1.540 +@param aIsSymbol ETrue if the typeface is a symbol typeface, otherwise EFalse. */
1.541 + {
1.542 + if (aIsSymbol)
1.543 + {
1.544 + iFlags |= ESymbol;
1.545 + }
1.546 + else
1.547 + {
1.548 + iFlags &= ~ESymbol;
1.549 + }
1.550 + }
1.551 +
1.552 +
1.553 +EXPORT_C TInt TTypeface::Attributes() const
1.554 +/** Gets the combination of attributes of the typeface.
1.555 +
1.556 +@return The combination of attributes of the typeface. */
1.557 + {
1.558 + return KTTypefaceMaskAttrib & iFlags;
1.559 + }
1.560 +
1.561 +
1.562 +EXPORT_C TBool TTypeface::IsProportional() const
1.563 +/** Gets the typeface's proportional attribute.
1.564 +
1.565 +@return ETrue if the typeface is proportional, EFalse otherwise. */
1.566 + {
1.567 + return KTTypefaceMaskAttrib & iFlags & EProportional;
1.568 + }
1.569 +
1.570 +
1.571 +EXPORT_C TBool TTypeface::IsSerif() const
1.572 +/** Gets the typeface's serif attribute.
1.573 +
1.574 +@return ETrue if the typeface is a serif typeface, EFalse otherwise */
1.575 + {
1.576 + return KTTypefaceMaskAttrib & iFlags & ESerif;
1.577 + }
1.578 +
1.579 +
1.580 +EXPORT_C TBool TTypeface::IsSymbol() const
1.581 +/** Gets the typeface's symbol attribute.
1.582 +
1.583 +@return ETrue if the typeface is a symbol typeface, EFalse otherwise */
1.584 + {
1.585 + return KTTypefaceMaskAttrib & iFlags & ESymbol;
1.586 + }
1.587 +
1.588 +
1.589 +/** Specifies the script with which font metrics calculation will be based on.
1.590 +@param aLanguage The language used to derive the required script.
1.591 +@internalTechnology
1.592 +*/
1.593 +EXPORT_C void TTypeface::SetScriptTypeForMetrics(TLanguage aLanguage)
1.594 + {
1.595 + SetScriptTypeForMetrics(GlyphSample::TLanguage2TScript(aLanguage));
1.596 + }
1.597 +
1.598 +/** Specifies the script with which font metrics calculation will be based on.
1.599 +@param aScript The script.
1.600 +@internalTechnology
1.601 +*/
1.602 +EXPORT_C void TTypeface::SetScriptTypeForMetrics(TInt aScript)
1.603 + {
1.604 + ResetScriptType();
1.605 + iFlags |= KTTypefaceMaskScript & (aScript << KTTypefaceBitsNumAttrib);
1.606 + }
1.607 +
1.608 +/** Gets the script with which font metrics calculation will be based on.
1.609 +@return The script.
1.610 +@internalTechnology
1.611 +*/
1.612 +EXPORT_C TInt TTypeface::ScriptTypeForMetrics() const
1.613 + {
1.614 + return (KTTypefaceMaskScript & iFlags) >> KTTypefaceBitsNumAttrib;
1.615 + }
1.616 +
1.617 +/**
1.618 +Sets the name of the typeface. This method should be used rather than
1.619 +directly accessing the iName public member.
1.620 +@param aName The name of the typeface (e.g. "Roman"). It should be no
1.621 + longer than KMaxTypefaceNameLength characters in length.
1.622 +@panic GDI 6, if aName is more than KMaxTypefaceNameLength characters
1.623 + long.
1.624 +*/
1.625 +EXPORT_C void TTypeface::SetName(const TDesC& aName)
1.626 + {
1.627 + TEXTBASE_ASSERT_ALWAYS(aName.Length() <= KMaxTypefaceNameLength, ETextBasePanic_TypefaceNameOverflow);
1.628 + iName=aName;
1.629 + }
1.630 +
1.631 +/**
1.632 +Returns the name of the typeface.
1.633 +@return The name of the typeface.
1.634 +*/
1.635 +EXPORT_C const TDesC& TTypeface::Name() const
1.636 + {
1.637 + return iName;
1.638 + }
1.639 +
1.640 +
1.641 +//
1.642 +// CFont
1.643 +//
1.644 +
1.645 +/** Default destructor. */
1.646 +EXPORT_C CFont::~CFont()
1.647 + {}
1.648 +
1.649 +_LIT(KGdiZeroCharacter,"0");
1.650 +
1.651 +/** Gets the width of the zero character of this font in pixels.
1.652 +
1.653 +This function is provided as the "0" character is roughly the average width
1.654 +of the characters of any font.
1.655 +
1.656 +@return The width of the "0" character, in pixels. */
1.657 +EXPORT_C TInt CFont::WidthZeroInPixels() const
1.658 + {
1.659 + return(TextWidthInPixels(KGdiZeroCharacter));
1.660 + }
1.661 +
1.662 +
1.663 +/** Gets the font descent in pixels.
1.664 +It is defined to be HeightInPixels() minus AscentInPixels().
1.665 +Note that this deprecated function is replaced by the new @c FontMaxDescent()
1.666 +or in some cases @c FontStandardDescent().
1.667 +
1.668 +@return The font descent in pixels.
1.669 +@see FontStandardDescent()
1.670 +@see FontMaxDescent()
1.671 +@deprecated */
1.672 +EXPORT_C TInt CFont::DoDescentInPixels() const
1.673 + {
1.674 + return HeightInPixels() - AscentInPixels();
1.675 + }
1.676 +
1.677 +
1.678 +/** Checks to see if the pen position needs to be included in the bounds
1.679 +calculation for purposes of considering side-bearings in the line break point
1.680 +
1.681 +@param aInput The input block. Contains the check flag and maxbounds.
1.682 +@param aPenPos The current value of the pen position.
1.683 +@param aBoundsBR Bottom-right bounds value.
1.684 +@param aBoundsTL Top-left bounds value.
1.685 +@return Whether or not MaxBounds has been exceeded
1.686 +*/
1.687 +LOCAL_C TBool BoundsExceeded(const CFont::TMeasureTextInput& aInput,
1.688 + const TInt& aPenPos, TInt& aBoundsBR, TInt& aBoundsTL)
1.689 + {
1.690 + if (aInput.iFlags & CFont::TMeasureTextInput::EFIncludePenPositionInBoundsCheck)
1.691 + {
1.692 + if (aInput.iFlags & CFont::TMeasureTextInput::EFVisualOrderRightToLeft)
1.693 + {
1.694 + aBoundsTL = Min(aBoundsTL, aPenPos);
1.695 + }
1.696 + else
1.697 + {
1.698 + aBoundsBR = Max(aBoundsBR, aPenPos);
1.699 + }
1.700 + }
1.701 + return (aBoundsBR - aBoundsTL > aInput.iMaxBounds);
1.702 + }
1.703 +
1.704 +
1.705 +/** Text measurement function.
1.706 +
1.707 +This is a powerful text measurement function underlying all the
1.708 +other text measurement functions. It takes optional input and output
1.709 +parameter blocks, which may be null, and returns the advance
1.710 +width (change in pen position when drawn horizontally) of the text, or the advance
1.711 +height, if the text is drawn vertically.
1.712 +
1.713 +Some of the functions that can be performed using this
1.714 +function are listed below. Many of them are used by the Text Views
1.715 +API to do its typographic layout.
1.716 +- Get the advance width or advance height (return value).
1.717 +The advance width is the amount by which the pen advances when drawing
1.718 +the text horizontally, while the advance height is the amount by which
1.719 +the pen advances when drawing the text vertically.
1.720 +- Measure some text in context, so that shaping behaviour
1.721 +(e.g. in Arabic) can be affected by what comes before and after the
1.722 +text. Do this using TMeasureTextInput::iStartInputChar and
1.723 +TMeasureTextInput::iEndInputChar to tell the function where to start and end
1.724 +in the supplied descriptor.
1.725 +- Determine how much text fits a given size by setting
1.726 +TMeasureTextInput::iMaxAdvance or TMeasureTextInput::iMaxBounds.
1.727 +- Specify letter spacing and word spacing using TMeasureTextInput::iCharJustNum,
1.728 +TMeasureTextInput::iCharJustExcess,
1.729 +TMeasureTextInput::iWordJustNum and
1.730 +TMeasureTextInput::iWordJustExcess.
1.731 +- Get the number of characters drawn in TMeasureTextOutput::iChars
1.732 +when applying the various constraints in TMeasureTextInput.
1.733 +- Get the number of glyphs drawn in TMeasureTextOutput::iGlyphs.
1.734 +- Get the number of groups (formed by ligation or diacritic placement) in
1.735 +TMeasureTextOutput::iGroups. Groups are units of cursor
1.736 +movement: the cursor hops over a character-plus-accent group or an
1.737 +Arabic or other ligature in one go.
1.738 +- Get the number of word spaces in TMeasureTextOutput::iSpaces.
1.739 +- Get the bounds of the inked-in pixels in TMeasureTextOutput::iBounds.
1.740 +- Get the size of the biggest glyph that would be drawn in TMeasureTextOutput::iMaxGlyphSize.
1.741 +
1.742 +@param aText The text to be measured.
1.743 +@param aInput The input block. This may be NULL.
1.744 +@param aOutput The output block. This may be NULL.
1.745 +@return The advance width if the text is drawn horizontally or the advance
1.746 +height if the text is drawn vertically.
1.747 +
1.748 +@panic GDI 1 In debug builds only, if TMeasureTextInput::iStartInputChar is negative.
1.749 +*/
1.750 +EXPORT_C TInt CFont::MeasureText(const TDesC& aText,const TMeasureTextInput* aInput,TMeasureTextOutput* aOutput) const
1.751 + {
1.752 + TMeasureTextInput input;
1.753 + if (aInput)
1.754 + input = *aInput;
1.755 + if (aOutput)
1.756 + {
1.757 + Mem::FillZ(aOutput,sizeof(*aOutput));
1.758 + aOutput->iChars = input.iStartInputChar;
1.759 + }
1.760 + TPositionParam param;
1.761 + param.iDirection = input.iDirection;
1.762 +
1.763 + TBool vertical = param.iDirection == EVertical;
1.764 + TBool penMovesLeft = EFalse;
1.765 + if (input.iFlags & TMeasureTextInput::EFVisualOrderRightToLeft)
1.766 + {
1.767 + if (!vertical)
1.768 + penMovesLeft = ETrue;
1.769 + param.iFlags |= TPositionParam::EFLogicalOrder;
1.770 + }
1.771 + else if (!(input.iFlags & TMeasureTextInput::EFVisualOrder))
1.772 + param.iFlags |= TPositionParam::EFLogicalOrder;
1.773 +
1.774 +
1.775 + param.iText.Set(aText);
1.776 +
1.777 + int advance = 0;
1.778 + int groups = 0;
1.779 + int spaces = 0;
1.780 + param.iPosInText = input.iStartInputChar;
1.781 + int end_char = Min(aText.Length(),input.iEndInputChar);
1.782 + TRect bounds;
1.783 + // Total advance if pen is moving left. Positive.
1.784 + TInt rightToLeftAdvance = 0;
1.785 + // Shaping information of the text
1.786 + RShapeInfo shapeInfo;
1.787 + while (param.iPosInText < end_char)
1.788 + {
1.789 + if (!GetCharacterPosition2(param, shapeInfo))
1.790 + {
1.791 + if (aOutput)
1.792 + aOutput->iChars = param.iPosInText;
1.793 + continue;
1.794 + }
1.795 +
1.796 + int new_advance = vertical ? param.iPen.iY : param.iPen.iX;
1.797 + if (input.iCharJustExcess != 0)
1.798 + new_advance += CGraphicsContext::JustificationInPixels(input.iCharJustExcess,input.iCharJustNum,groups,1);
1.799 + groups++;
1.800 + // Allow justification to occur at spaces
1.801 + if (param.iOutput[0].iCode == 0x0020)
1.802 + {
1.803 + if (input.iWordJustExcess != 0)
1.804 + new_advance += CGraphicsContext::JustificationInPixels(input.iWordJustExcess,input.iWordJustNum,spaces,1);
1.805 + spaces++;
1.806 + }
1.807 + if (vertical)
1.808 + param.iPen.iY = new_advance;
1.809 + else
1.810 + param.iPen.iX = new_advance;
1.811 +
1.812 + if (penMovesLeft)
1.813 + {
1.814 + // If the pen is moving left, we will begin each cluster at (0,0)
1.815 + // and shift the bounds to the right to compensate.
1.816 + bounds.iTl.iX += param.iPen.iX;
1.817 + bounds.iBr.iX += param.iPen.iX;
1.818 + bounds.iTl.iY += param.iPen.iY;
1.819 + bounds.iBr.iY += param.iPen.iY;
1.820 + rightToLeftAdvance += param.iPen.iX;
1.821 + new_advance = rightToLeftAdvance;
1.822 + param.iPen.iX = 0;
1.823 + param.iPen.iY = 0;
1.824 + }
1.825 +
1.826 + if (aInput || aOutput)
1.827 + {
1.828 + const TPositionParam::TOutput* output = param.iOutput;
1.829 + for (int i = 0; i < param.iOutputGlyphs; i++, output++)
1.830 + {
1.831 + //if (!output->iBounds.IsEmpty()) -- optimized to:
1.832 + if (output->iBounds.iTl.iX != output->iBounds.iBr.iX
1.833 + || output->iBounds.iTl.iY != output->iBounds.iBr.iY)
1.834 + {
1.835 + if (aOutput)
1.836 + {
1.837 + // increase iMaxGlyphSize if either dimension smaller than
1.838 + // current glyph
1.839 + TInt boundsDim = output->iBounds.iBr.iX - output->iBounds.iTl.iX;
1.840 + aOutput->iMaxGlyphSize.iWidth = aOutput->iMaxGlyphSize.iWidth < boundsDim?
1.841 + boundsDim : aOutput->iMaxGlyphSize.iWidth;
1.842 + boundsDim = output->iBounds.iBr.iY - output->iBounds.iTl.iY;
1.843 + aOutput->iMaxGlyphSize.iHeight = aOutput->iMaxGlyphSize.iHeight < boundsDim?
1.844 + boundsDim : aOutput->iMaxGlyphSize.iHeight;
1.845 + }
1.846 + //bounds.BoundingRect(output->iBounds); -- optimized to:
1.847 + if (output->iBounds.iTl.iX < bounds.iTl.iX)
1.848 + bounds.iTl.iX = output->iBounds.iTl.iX;
1.849 + if (bounds.iBr.iX < output->iBounds.iBr.iX)
1.850 + bounds.iBr.iX = output->iBounds.iBr.iX;
1.851 + if (output->iBounds.iTl.iY < bounds.iTl.iY)
1.852 + bounds.iTl.iY = output->iBounds.iTl.iY;
1.853 + if (bounds.iBr.iY < output->iBounds.iBr.iY)
1.854 + bounds.iBr.iY = output->iBounds.iBr.iY;
1.855 + }
1.856 + }
1.857 +
1.858 + // Would any limits be exceeded by adding this group?
1.859 + if (param.iPosInText > end_char)
1.860 + break;
1.861 + if (new_advance > input.iMaxAdvance)
1.862 + break;
1.863 + if (vertical)
1.864 + {
1.865 + if (BoundsExceeded(input, param.iPen.iY, bounds.iBr.iY, bounds.iTl.iY))
1.866 + break;
1.867 + }
1.868 + else
1.869 + {
1.870 + if (BoundsExceeded(input, param.iPen.iX, bounds.iBr.iX, bounds.iTl.iX))
1.871 + break;
1.872 + }
1.873 +
1.874 + if (aOutput)
1.875 + {
1.876 + aOutput->iChars = param.iPosInText; // should this not be aOutput->iChars = param.iPosInText - input.iShartInputChar;?
1.877 + aOutput->iGlyphs += param.iOutputGlyphs;
1.878 + aOutput->iGroups = groups;
1.879 + aOutput->iSpaces = spaces;
1.880 + aOutput->iBounds = bounds;
1.881 + }
1.882 + }
1.883 +
1.884 + advance = new_advance;
1.885 + }
1.886 + if(shapeInfo.IsOpen())
1.887 + shapeInfo.Close();
1.888 + return advance;
1.889 + }
1.890 +
1.891 +// These 3 functions should probably be moved to E32/Euser as part of TChar or
1.892 +// similar as there seem to be several local copies of similar functions in
1.893 +// various OS modules so we should remove duplication
1.894 +
1.895 +TUint16 HighSurrogate(TUint aCode)
1.896 + {
1.897 + TEXTBASE_ASSERT_DEBUG(aCode > 0xFFFF, ETextBasePanic_InvalidInputParam);
1.898 + return STATIC_CAST(TUint16, 0xD7C0 + (aCode >> 10));
1.899 + }
1.900 +
1.901 +TUint16 LowSurrogate(TUint aCode)
1.902 + {
1.903 + TEXTBASE_ASSERT_DEBUG(aCode > 0xFFFF, ETextBasePanic_InvalidInputParam);
1.904 + return STATIC_CAST(TUint16, 0xDC00 | (aCode & 0x3FF));
1.905 + }
1.906 +
1.907 +TUint CombineSurrogates(TUint aHighSurrogate, TUint aLowSurrogate)
1.908 + {
1.909 + TEXTBASE_ASSERT_DEBUG((0xD800 == (aHighSurrogate & 0xF800)), ETextBasePanic_InvalidInputParam);
1.910 + TEXTBASE_ASSERT_DEBUG((0xD800 == (aHighSurrogate & 0xFC00)), ETextBasePanic_InvalidInputParam);
1.911 + TEXTBASE_ASSERT_DEBUG((0xDC00 == (aLowSurrogate & 0xFC00)), ETextBasePanic_InvalidInputParam);
1.912 + return ((aHighSurrogate - 0xD7F7) << 10) + aLowSurrogate;
1.913 + }
1.914 +
1.915 +
1.916 +/** Overridable function innards of GetCharacterPosition and
1.917 +GetCharacterPosition2. It is generally not useful to override this function.
1.918 +@publishedAll
1.919 +@see GetCharacterPosition
1.920 +@see GetCharacterPosition2
1.921 +*/
1.922 +EXPORT_C TBool CFont::DoGetCharacterPosition(TPositionParam& aParam) const
1.923 + {
1.924 + RShapeInfo shapeInfo;
1.925 + TBool r = GetCharacterPosition2(aParam, shapeInfo);
1.926 + if (shapeInfo.IsOpen())
1.927 + shapeInfo.Close();
1.928 + return r;
1.929 + }
1.930 +
1.931 +// Find the script (and hence the correct process function) that any punctuation or digit may belong to
1.932 +LOCAL_C GlyphSelection::ProcessFunc FindContextualProcessFunc(RShapeInfo& aShapeInfo, const TGlyphSelectionState aGss)
1.933 + {
1.934 + GlyphSelection::ProcessFunc processFunc = CharacterToProcessFunction(aGss.iCodeChar);
1.935 + GlyphSelection::ProcessFunc contextProcessFunc = (GlyphSelection::ProcessFunc)aShapeInfo.GetContext();
1.936 +
1.937 + // If context or prevCode is NULL, use processFunc,
1.938 + // else use function of context or prevCode
1.939 + if ((aGss.iCodeChar.IsDigit() || aGss.iCodeChar.IsPunctuation()) && !QuoteOrBracketPair(aGss.iCodeChar) && processFunc!=GlyphSelector_SoftHyphen::Process)
1.940 + {
1.941 + // If context is not set, check the previous char for context.
1.942 + if (contextProcessFunc == NULL)
1.943 + {
1.944 + if (aGss.iParam.iPosInText > 0)
1.945 + {
1.946 + TChar prevCode = aGss.iText.Get(-1);
1.947 + GlyphSelection::ProcessFunc prevProcessFunc = CharacterToProcessFunction(prevCode);
1.948 + if (prevProcessFunc != NULL && (prevCode.IsAlpha() || prevProcessFunc != GlyphSelector_Default::Process))
1.949 + {
1.950 + aShapeInfo.SetContext((TAny *)prevProcessFunc);
1.951 + return prevProcessFunc;
1.952 + }
1.953 + }
1.954 + }
1.955 + else
1.956 + return contextProcessFunc;
1.957 +
1.958 + return processFunc;
1.959 + }
1.960 +
1.961 + // set the context with current processFunc only if current char is not ignored for context.
1.962 + if (processFunc != NULL && (aGss.iCodeChar.IsAlpha() || processFunc != GlyphSelector_Default::Process))
1.963 + aShapeInfo.SetContext((TAny *)processFunc);
1.964 + return processFunc;
1.965 + }
1.966 +
1.967 +/** Takes Unicode text and produces the glyph cluster for the first character
1.968 +in that text plus any combining mark characters, or for the first indic
1.969 +syllable. It is responsible for contextual glyph selection, ligature creation
1.970 +and diacritic placement.
1.971 +
1.972 +@param aParam
1.973 + The input/output parameter of the text/glyph data for the algorithm.
1.974 +@param aShapeInfo
1.975 + The function will cache "shaped" text (e.g. complex scripts such as
1.976 + Devanagari) here. aShapeInfo must be freshly-constructed or closed for each
1.977 + new piece of text in aParam.iText. If aParam.iText is unchanged between
1.978 + calls, aShapeInfo should be passed back in unchanged as well.
1.979 +@return
1.980 + ETrue if glyphs for supplied text have been produced, EFalse in failure.
1.981 +@see CFont::TPositionParam
1.982 +@publishedAll
1.983 +@released */
1.984 +EXPORT_C TBool CFont::GetCharacterPosition2(TPositionParam& aParam, RShapeInfo& aShapeInfo) const
1.985 + {
1.986 + TEXTBASE_ASSERT_DEBUG(aParam.iPosInText>=0, ETextBasePanic_InvalidInputParam);
1.987 + TEXTBASE_ASSERT_DEBUG(aParam.iText.Ptr(), ETextBasePanic_InvalidInputParam);
1.988 +
1.989 + aParam.iOutputGlyphs = 0;
1.990 + TInt textLen = aParam.iText.Length();
1.991 + TBool outputOk = ETrue;
1.992 + TPoint penCopy = aParam.iPen;
1.993 +
1.994 + // Verify input parameters are sane
1.995 + if (aParam.iPosInText >= textLen)
1.996 + return EFalse;
1.997 +
1.998 + // Setup glyph selection algorithm data
1.999 + TUtf32Iterator textIter(aParam.iText.Ptr(), aParam.iText.Ptr()+textLen, aParam.iPosInText);
1.1000 + if (textIter.AtEnd())
1.1001 + {
1.1002 + aParam.iPosInText = textIter.LengthToStart();
1.1003 + return outputOk;
1.1004 + }
1.1005 +
1.1006 + // Process each character in the text in turn until we reach the end of
1.1007 + // the iterator, the next base (non-mark/combining) character or reach
1.1008 + // the limit in a glyph cluster.
1.1009 + GlyphSelection::ProcessFunc firstProcessFn = 0;
1.1010 + TGlyphSelectionState gss(textIter, this, aParam);
1.1011 + do
1.1012 + {
1.1013 + // Retrieve character info for processing.
1.1014 + gss.iCodePt = gss.iCodeChar = textIter.Get();
1.1015 + gss.iCombCls = gss.iCodeChar.GetCombiningClass();
1.1016 + gss.iCats = gss.iCodeChar.GetCategory();
1.1017 + gss.iClusterState = TGlyphSelectionState::EGClusterNotComplete;
1.1018 + gss.iPen = TGlyphSelectionState::EPenAdvance_No;
1.1019 +
1.1020 + // Find the correct processesing function for the script being used.
1.1021 + // If gss.iCodePt is a strongly directional character, then simply map it in TTableEntry Table[]
1.1022 + // and use the returned process function pointer.
1.1023 + // If gss.iCodePt is a punctuation or a digit, then use a context character in the text (if
1.1024 + // available) to find the contextual script being rendered and use its process function pointer.
1.1025 + GlyphSelection::ProcessFunc processFn = FindContextualProcessFunc(aShapeInfo, gss);
1.1026 +
1.1027 + if (!firstProcessFn)
1.1028 + firstProcessFn = processFn;
1.1029 +
1.1030 + if (processFn)
1.1031 + {
1.1032 + if (firstProcessFn == processFn)
1.1033 + outputOk = processFn(gss, aShapeInfo);
1.1034 + else
1.1035 + break;
1.1036 + }
1.1037 + else
1.1038 + {
1.1039 + // Table entry blank, unicode char to be skipped
1.1040 + outputOk = ETrue;
1.1041 + textIter.Next();
1.1042 + gss.iClusterState =
1.1043 + (!textIter.AtEnd() &&
1.1044 + ((textIter.Get().GetCategory() & 0xF0)
1.1045 + == TChar::EMarkGroup)) ?
1.1046 + TGlyphSelectionState::EGClusterNotComplete : TGlyphSelectionState::EGClusterComplete;
1.1047 + }
1.1048 +
1.1049 + // Abort if no class was available to process the character or if
1.1050 + // processing failed.
1.1051 + if (!outputOk)
1.1052 + {
1.1053 + aParam.iPosInText = textIter.LengthToStart();
1.1054 + return outputOk;
1.1055 + }
1.1056 +
1.1057 + // Did the glyph selector that processed the character want the
1.1058 + // pen to advance?
1.1059 + if (gss.iPen == TGlyphSelectionState::EPenAdvance_Yes)
1.1060 + {
1.1061 + aParam.iPen.iX += gss.iAdvance.iWidth;
1.1062 + aParam.iPen.iY += gss.iAdvance.iHeight;
1.1063 + gss.iPen = TGlyphSelectionState::EPenAdvance_No;
1.1064 + }
1.1065 +
1.1066 + // Here we assume the Process() methods have advanced the iterator as
1.1067 + // they consume characters they handle so that it now points to the
1.1068 + // character to process next time around the loop.
1.1069 + }
1.1070 + while (!textIter.AtEnd() // We still have more text to process
1.1071 + && (gss.iClusterState == TGlyphSelectionState::EGClusterNotComplete) // Glyph cluster !complete
1.1072 + && (aParam.iOutputGlyphs < TPositionParam::EMaxOutputGlyphs)); // Room for another glyph entry
1.1073 +
1.1074 + // If a complete glyph cluster has been identified then we should try to
1.1075 + // compose it as fully as possible. Obviously, if it only contains one
1.1076 + // character then it is already fully composed so we can ignore it.
1.1077 + // Skip this if any language-specific processing has taken place.
1.1078 + if (gss.iGlyphPostCombine == TGlyphSelectionState::EGPostCombine_Yes
1.1079 + && gss.iClusterState == TGlyphSelectionState::EGClusterComplete)
1.1080 + {
1.1081 + // Leave room to handle surrogates - Decompose() outputs UTF-16
1.1082 + // The max that can come out of the previous stage is TPositionParam::EMaxOutputGlyphs
1.1083 + // long with only one base char at the start. Even if that base char decomposed to the
1.1084 + // max it could only be MaxOutputGlyphs long, giving a total of (2 * MaxOutputGlyphs)-1
1.1085 + // Conceivably the use of surrogates throughout could double that when converting to UTF-16
1.1086 + TBuf<TPositionParam::EMaxOutputGlyphs * 4> decomposeArray;
1.1087 + TBool success = ETrue;
1.1088 + // Go through the glyph cluster one char at a time
1.1089 + for (TInt i = 0; i < aParam.iOutputGlyphs; i++)
1.1090 + {
1.1091 + TChar singleChar(aParam.iOutput[i].iCode);
1.1092 + // If first character try to decompose it otherwise just take the character
1.1093 + TBool decomposed = EFalse;
1.1094 + TPtrC16 decomposition;
1.1095 + if (i == 0)
1.1096 + decomposed = singleChar.Decompose(decomposition);
1.1097 + if (decomposed)
1.1098 + { // Pick up the sequence of characters
1.1099 + decomposeArray.Append(decomposition);
1.1100 + }
1.1101 + else
1.1102 + { // Keep the original character
1.1103 + if (singleChar > 0xFFFF)
1.1104 + { // Above the BMP so we need a surrogate pair for UTF-16
1.1105 + // This calculation really ought to go into a separate routine - probably part of TChar
1.1106 + decomposeArray.Append(HighSurrogate(singleChar));
1.1107 + decomposeArray.Append(LowSurrogate(singleChar));
1.1108 + }
1.1109 + else
1.1110 + { // It's not a surrogate so we just need to cast it down (since it's safe)
1.1111 + decomposeArray.Append(singleChar);
1.1112 + }
1.1113 + }
1.1114 + // Guard against bad input overflowing the array and causing a panic
1.1115 + if (decomposeArray.Length() > (TPositionParam::EMaxOutputGlyphs * 4) - 2)
1.1116 + { // too long to be a viable composition so don't try
1.1117 + success = EFalse;
1.1118 + break;
1.1119 + }
1.1120 + }
1.1121 + TUint composedChar = 0;
1.1122 + TOpenFontCharMetrics metrics;
1.1123 + TPositionParam::TOutput output;
1.1124 + TSize advance; // gets initialized to 0,0
1.1125 + if (success)
1.1126 + {
1.1127 + //Now try and compose the string to a single character
1.1128 + success = TChar::Compose(composedChar, decomposeArray);
1.1129 + }
1.1130 + if (success)
1.1131 + {
1.1132 + // if single char is not in font or can't get char metrics for it
1.1133 + // N.B. This will probably always return metrics because if the
1.1134 + // char is not in the font this will usually return the substitute
1.1135 + // "missing" glyph (and its metrics). There should be a function to
1.1136 + // really tell you if a glyph is in the font - but there isn't.
1.1137 + if (GetCharacterData(composedChar, metrics, output.iBitmap, output.iBitmapSize) == CFont::ENoCharacterData)
1.1138 + success = EFalse;
1.1139 + }
1.1140 + if (success)
1.1141 + {
1.1142 + // We should replace the glyph cluster made from multiple chars
1.1143 + // with the correct single char and fix up the rest of the output
1.1144 + // parameters as well
1.1145 + output.iCode = composedChar;
1.1146 + // Set the glyph's bounds and record pen advancement.
1.1147 + if (aParam.iDirection == CFont::EVertical)
1.1148 + {
1.1149 + metrics.GetVertBounds(output.iBounds);
1.1150 + advance.iHeight = metrics.VertAdvance();
1.1151 + }
1.1152 + else
1.1153 + {
1.1154 + metrics.GetHorizBounds(output.iBounds);
1.1155 + advance.iWidth = metrics.HorizAdvance();
1.1156 + }
1.1157 + // Adjust the glyph's bounding box to offset it from the pen
1.1158 + // position (origin of drawing). For speed increment directly.
1.1159 + output.iBounds.iTl.iX += penCopy.iX;
1.1160 + output.iBounds.iBr.iX += penCopy.iX;
1.1161 + output.iBounds.iTl.iY += penCopy.iY;
1.1162 + output.iBounds.iBr.iY += penCopy.iY;
1.1163 + // Set penCopy, the copy of aParam.iPen that we made
1.1164 + penCopy.iX += advance.iWidth;
1.1165 + penCopy.iY += advance.iHeight;
1.1166 + // Overwrite the original output parameters for the glyph cluster
1.1167 + // with the values for the single composed character
1.1168 + aParam.iOutput[0] = output;
1.1169 + aParam.iOutputGlyphs = 1;
1.1170 + aParam.iPen = penCopy;
1.1171 + }
1.1172 + }
1.1173 +
1.1174 + // Exit routine with result and increment position in text to
1.1175 + // where we reached during processing to avoid any caller loops from
1.1176 + // infinite execution.
1.1177 + aParam.iPosInText = textIter.LengthToStart();
1.1178 + return outputOk;
1.1179 + }
1.1180 +
1.1181 +/** Gets the character metrics for a character.
1.1182 +
1.1183 +@param aCode The character code.
1.1184 +@param aMetrics On return, contains the character bitmap.
1.1185 +@param aBitmap On return, this points to NULL.
1.1186 +@param aBitmapSize On return, this has a size of (0,0).
1.1187 +@return ECharacterWidthOnly
1.1188 +*/
1.1189 +EXPORT_C CFont::TCharacterDataAvailability CFont::DoGetCharacterData(TUint aCode,TOpenFontCharMetrics& aMetrics,
1.1190 + const TUint8*& aBinaryData,TSize& aBitmapSize) const
1.1191 + {
1.1192 + int width = CharWidthInPixels(aCode);
1.1193 + aMetrics.SetHorizAdvance(width);
1.1194 + aBinaryData = NULL;
1.1195 + // For speed set to 0 directly rather than call SetSize()
1.1196 + aBitmapSize.iWidth = 0;
1.1197 + aBitmapSize.iHeight = 0;
1.1198 +
1.1199 + /*
1.1200 + Set the other metrics using the width and font metrics.
1.1201 + This allows derived classes that don't override this function, like CInfoFont,
1.1202 + to give usable results for TextWidthInPixels and MeasureText.
1.1203 + */
1.1204 + aMetrics.SetWidth(width);
1.1205 + int height = HeightInPixels();
1.1206 + aMetrics.SetHeight(height);
1.1207 + aMetrics.SetVertAdvance(height);
1.1208 + aMetrics.SetHorizBearingX(0);
1.1209 + aMetrics.SetHorizBearingY(AscentInPixels());
1.1210 + aMetrics.SetVertBearingX(0);
1.1211 + aMetrics.SetVertBearingY(0);
1.1212 +
1.1213 + return CFont::ECharacterWidthOnly;
1.1214 + }
1.1215 +
1.1216 +
1.1217 +/** Determines if aLeftCharacter and aRightCharacter affect each other's
1.1218 +contextual glyph form if placed next to each other. If either character
1.1219 +is a combining character, EFalse will be returned, which is not generally
1.1220 +useful information. Pass in base characters ignoring intervening combining
1.1221 +characters.
1.1222 +@param aLeftCharacter Unicode code for the character that stands on the left.
1.1223 +@param aRightCharacter Unicode code for the character that stands on the right.
1.1224 +@return EFalse if the characters do not affect the contextual glyphs that are
1.1225 +be chosen when the two are rendered together, compared to being separated
1.1226 +(for example by a space). */
1.1227 +EXPORT_C TBool CFont::CharactersJoin(TInt aLeftCharacter, TInt aRightCharacter)
1.1228 + {
1.1229 + return GlyphSelector_Arabic::CharactersJoin(aLeftCharacter, aRightCharacter);
1.1230 + }
1.1231 +
1.1232 +/** API extension system that enables the caller to access a particular API
1.1233 +extension function. N.B. Any overload of this function in a derived class
1.1234 +should call its immediate parent implementation for any extension function Uid
1.1235 +that it does not recognize and handle.
1.1236 +@param aInterfaceId UID of the required extension function
1.1237 +@param aParam Pointer to an arbitrary parameter block that can be used to
1.1238 +provide and/or return information to/from the particular extension function,
1.1239 +defaults to NULL.
1.1240 +@return Integer return value from extension function
1.1241 +@internalTechnology
1.1242 +@released
1.1243 +*/
1.1244 +EXPORT_C TInt CFont::DoExtendedFunction(TUid aFunctionId, TAny* /* aParam */) const
1.1245 + {
1.1246 + if (KFontCapitalAscent == aFunctionId ||
1.1247 + KFontMaxAscent == aFunctionId)
1.1248 + {
1.1249 + return AscentInPixels();
1.1250 + }
1.1251 + else if (KFontStandardDescent == aFunctionId ||
1.1252 + KFontMaxDescent == aFunctionId)
1.1253 + {
1.1254 + return DescentInPixels();
1.1255 + }
1.1256 + else if (KFontLineGap == aFunctionId)
1.1257 + { // 1.2 of em height (rounded) is reasonable approximation of interline gap
1.1258 + return (HeightInPixels() * 12 + 5) / 10;
1.1259 + }
1.1260 + return KErrNotFound;
1.1261 + }
1.1262 +
1.1263 +EXPORT_C TUid CFont::TypeUid() const
1.1264 + {
1.1265 + return DoTypeUid();
1.1266 + }
1.1267 +
1.1268 +EXPORT_C TInt CFont::HeightInPixels() const
1.1269 + {
1.1270 + return DoHeightInPixels();
1.1271 + }
1.1272 +
1.1273 +EXPORT_C TInt CFont::AscentInPixels() const
1.1274 + {
1.1275 + return DoAscentInPixels();
1.1276 + }
1.1277 +
1.1278 +EXPORT_C TInt CFont::DescentInPixels() const
1.1279 + {
1.1280 + return DoDescentInPixels();
1.1281 + }
1.1282 +
1.1283 +EXPORT_C TInt CFont::CharWidthInPixels(TChar aChar) const
1.1284 + {
1.1285 + return DoCharWidthInPixels(aChar);
1.1286 + }
1.1287 +
1.1288 +EXPORT_C TInt CFont::TextWidthInPixels(const TDesC& aText) const
1.1289 + {
1.1290 + return DoTextWidthInPixels(aText);
1.1291 + }
1.1292 +
1.1293 +EXPORT_C TInt CFont::BaselineOffsetInPixels() const
1.1294 + {
1.1295 + return DoBaselineOffsetInPixels();
1.1296 + }
1.1297 +
1.1298 +EXPORT_C TInt CFont::TextCount(const TDesC& aText,TInt aWidthInPixels) const
1.1299 + {
1.1300 + return DoTextCount(aText, aWidthInPixels);
1.1301 + }
1.1302 +
1.1303 +EXPORT_C TInt CFont::TextCount(const TDesC& aText, TInt aWidthInPixels, TInt& aExcessWidthInPixels) const
1.1304 + {
1.1305 + return DoTextCount(aText, aWidthInPixels, aExcessWidthInPixels);
1.1306 + }
1.1307 +
1.1308 +EXPORT_C TInt CFont::MaxCharWidthInPixels() const
1.1309 + {
1.1310 + return DoMaxCharWidthInPixels();
1.1311 + }
1.1312 +
1.1313 +EXPORT_C TInt CFont::MaxNormalCharWidthInPixels() const
1.1314 + {
1.1315 + return DoMaxNormalCharWidthInPixels();
1.1316 + }
1.1317 +
1.1318 +EXPORT_C TFontSpec CFont::FontSpecInTwips() const
1.1319 + {
1.1320 + return DoFontSpecInTwips();
1.1321 + }
1.1322 +
1.1323 +/** Gets the character metrics for a character.
1.1324 +
1.1325 +@param aCode The character code.
1.1326 +@param aMetrics On return, contains the character bitmap.
1.1327 +@param aBitmap On return, this points to NULL.
1.1328 +@param aBitmapSize On return, this has a size of (0,0).
1.1329 +@return ECharacterWidthOnly
1.1330 +*/
1.1331 +EXPORT_C CFont::TCharacterDataAvailability CFont::GetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics, const TUint8*& aBitmap, TSize& aBitmapSize) const
1.1332 + {
1.1333 + return DoGetCharacterData(aCode, aMetrics, aBitmap, aBitmapSize);
1.1334 + }
1.1335 +
1.1336 +/** Transforms one cluster of characters (base character plus combining marks,
1.1337 +ligature or indic syllable) into one cluster of glyphs together with their
1.1338 +positions. Repeated calls of this function (for the same input text) are
1.1339 +considerably slower than repeated calls of GetCharacterPosition2 for Indic text
1.1340 +(such as Hindi), as GetCharacterPosition2 can cache information between calls.
1.1341 +@param aParam Input and output parameters
1.1342 +@return True for success
1.1343 +@see GetCharacterPosition2
1.1344 +@publishedAll */
1.1345 +EXPORT_C TBool CFont::GetCharacterPosition(TPositionParam& aParam) const
1.1346 + {
1.1347 + return DoGetCharacterPosition(aParam);
1.1348 + }
1.1349 +
1.1350 +/** Enables the caller to access a particular API
1.1351 +extension function. N.B. Any overload of this function in a derived class
1.1352 +should call its immediate parent implementation for any extension function UID
1.1353 +that it does not recognize and handle.
1.1354 +@param aFunctionId UID of the required extension function
1.1355 +@param aParam Pointer to an arbitrary parameter block that can be used to
1.1356 +provide and/or return information to/from the particular extension function,
1.1357 +defaults to NULL.
1.1358 +@return Integer return value from extension function
1.1359 +*/
1.1360 +EXPORT_C TInt CFont::ExtendedFunction(TUid aFunctionId, TAny* aParam) const
1.1361 + {
1.1362 + return DoExtendedFunction(aFunctionId, aParam);
1.1363 + }
1.1364 +
1.1365 +EXPORT_C TInt CFont::TextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam) const
1.1366 + {
1.1367 + TTextWidthInternal context;
1.1368 + TTextWidthInternal* contextPtr = &context;
1.1369 + contextPtr->iText.Set(aText);
1.1370 + contextPtr->iParam.iStartInputChar = aParam->iStartInputChar;
1.1371 + contextPtr->iParam.iEndInputChar = aParam->iEndInputChar;
1.1372 + return DoExtendedFunction(KTextInContextWidthInPixelsUid, (TAny*)contextPtr);
1.1373 + }
1.1374 +
1.1375 +/**
1.1376 +Maps TLanguage to TScript.
1.1377 +
1.1378 +EScriptOther represents languages not yet supported in KTScript2GlyphSample.
1.1379 +This array does not handle ELangNone and ELangMaximum to save storage space.
1.1380 +*/
1.1381 +const TInt GlyphSample::KTLanguage2TScript[] =
1.1382 + {
1.1383 + EScriptNone, // 00 ELangTest
1.1384 + EScriptLatin, // 01 ELangEnglish
1.1385 + EScriptLatin, // 02 ELangFrench
1.1386 + EScriptLatin, // 03 ELangGerman
1.1387 + EScriptLatin, // 04 ELangSpanish
1.1388 + EScriptLatin, // 05 ELangItalian
1.1389 + EScriptLatin, // 06 ELangSwedish
1.1390 + EScriptLatin, // 07 ELangDanish
1.1391 + EScriptLatin, // 08 ELangNorwegian
1.1392 + EScriptLatin, // 09 ELangFinnish
1.1393 + EScriptLatin, // 10 ELangAmerican
1.1394 + EScriptLatin, // 11 ELangSwissFrench
1.1395 + EScriptLatin, // 12 ELangSwissGerman
1.1396 + EScriptLatin, // 13 ELangPortuguese
1.1397 + EScriptLatin, // 14 ELangTurkish
1.1398 + EScriptLatin, // 15 ELangIcelandic
1.1399 + EScriptCyrillic, // 16 ELangRussian
1.1400 + EScriptLatin, // 17 ELangHungarian
1.1401 + EScriptLatin, // 18 ELangDutch
1.1402 + EScriptLatin, // 19 ELangBelgianFlemish
1.1403 + EScriptLatin, // 20 ELangAustralian
1.1404 + EScriptLatin, // 21 ELangBelgianFrench
1.1405 + EScriptLatin, // 22 ELangAustrian
1.1406 + EScriptLatin, // 23 ELangNewZealand
1.1407 + EScriptLatin, // 24 ELangInternationalFrench
1.1408 + EScriptLatin, // 25 ELangCzech
1.1409 + EScriptLatin, // 26 ELangSlovak
1.1410 + EScriptLatin, // 27 ELangPolish
1.1411 + EScriptLatin, // 28 ELangSlovenian
1.1412 + EScriptHanIdeographs, // 29 ELangTaiwanChinese
1.1413 + EScriptHanIdeographs, // 30 ELangHongKongChinese
1.1414 + EScriptHanIdeographs, // 31 ELangPrcChinese
1.1415 + EScriptHanIdeographs, // 32 ELangJapanese
1.1416 + EScriptThai, // 33 ELangThai
1.1417 + EScriptLatin, // 34 ELangAfrikaans
1.1418 + EScriptLatin, // 35 ELangAlbanian
1.1419 + EScriptOther, // 36 ELangAmharic
1.1420 + EScriptArabic, // 37 ELangArabic
1.1421 + EScriptOther, // 38 ELangArmenian
1.1422 + EScriptOther, // 39 ELangTagalog
1.1423 + EScriptCyrillic, // 40 ELangBelarussian
1.1424 + EScriptOther, // 41 ELangBengali
1.1425 + EScriptCyrillic, // 42 ELangBulgarian
1.1426 + EScriptOther, // 43 ELangBurmese
1.1427 + EScriptLatin, // 44 ELangCatalan
1.1428 + EScriptLatin, // 45 ELangCroatian
1.1429 + EScriptLatin, // 46 ELangCanadianEnglish
1.1430 + EScriptLatin, // 47 ELangInternationalEnglish
1.1431 + EScriptLatin, // 48 ELangSouthAfricanEnglish
1.1432 + EScriptLatin, // 49 ELangEstonian
1.1433 + EScriptArabic, // 50 ELangFarsi
1.1434 + EScriptLatin, // 51 ELangCanadianFrench
1.1435 + EScriptLatin, // 52 ELangScotsGaelic
1.1436 + EScriptOther, // 53 ELangGeorgian
1.1437 + EScriptGreek, // 54 ELangGreek
1.1438 + EScriptGreek, // 55 ELangCyprusGreek
1.1439 + EScriptOther, // 56 ELangGujarati
1.1440 + EScriptHebrew, // 57 ELangHebrew
1.1441 + EScriptDevanagari, // 58 ELangHindi
1.1442 + EScriptLatin, // 59 ELangIndonesian
1.1443 + EScriptLatin, // 60 ELangIrish
1.1444 + EScriptLatin, // 61 ELangSwissItalian
1.1445 + EScriptOther, // 62 ELangKannada
1.1446 + EScriptCyrillic, // 63 ELangKazakh
1.1447 + EScriptOther, // 64 ELangKhmer
1.1448 + EScriptHanIdeographs, // 65 ELangKorean
1.1449 + EScriptOther, // 66 ELangLao
1.1450 + EScriptLatin, // 67 ELangLatvian
1.1451 + EScriptLatin, // 68 ELangLithuanian
1.1452 + EScriptCyrillic, // 69 ELangMacedonian
1.1453 + EScriptLatin, // 70 ELangMalay
1.1454 + EScriptOther, // 71 ELangMalayalam
1.1455 + EScriptDevanagari, // 72 ELangMarathi
1.1456 + EScriptLatin, // 73 ELangMoldavian
1.1457 + EScriptOther, // 74 ELangMongolian
1.1458 + EScriptLatin, // 75 ELangNorwegianNynorsk
1.1459 + EScriptLatin, // 76 ELangBrazilianPortuguese
1.1460 + EScriptOther, // 77 ELangPunjabi
1.1461 + EScriptLatin, // 78 ELangRomanian
1.1462 + EScriptCyrillic, // 79 ELangSerbian
1.1463 + EScriptOther, // 80 ELangSinhalese
1.1464 + EScriptLatin, // 81 ELangSomali
1.1465 + EScriptLatin, // 82 ELangInternationalSpanish
1.1466 + EScriptLatin, // 83 ELangLatinAmericanSpanish
1.1467 + EScriptLatin, // 84 ELangSwahili
1.1468 + EScriptLatin, // 85 ELangFinlandSwedish
1.1469 + EScriptNone, // 86 ELangReserved1
1.1470 + EScriptOther, // 87 ELangTamil
1.1471 + EScriptOther, // 88 ELangTelugu
1.1472 + EScriptOther, // 89 ELangTibetan
1.1473 + EScriptOther, // 90 ELangTigrinya
1.1474 + EScriptLatin, // 91 ELangCyprusTurkish
1.1475 + EScriptCyrillic, // 92 ELangTurkmen
1.1476 + EScriptCyrillic, // 93 ELangUkrainian
1.1477 + EScriptArabic, // 94 ELangUrdu
1.1478 + EScriptNone, // 95 ELangReserved2
1.1479 + EScriptLatin, // 96 ELangVietnamese
1.1480 + EScriptLatin, // 97 ELangWelsh
1.1481 + EScriptLatin, // 98 ELangZulu
1.1482 + };
1.1483 +
1.1484 +/**
1.1485 +Maps TScript to glyph samples.
1.1486 +
1.1487 +The order of samples definition has to follow the script order in TScript.
1.1488 +
1.1489 +Supported scripts Fonts used to experiment/determine glyph samples
1.1490 +
1.1491 +Latin Arial, Times, Century
1.1492 +Greek Ditto
1.1493 +Cyrillic Ditto
1.1494 +Hebrew Aharoni, David, FrankRuehl, Levenim MT, Miriam, Narkisim, Rod
1.1495 +Arabic Andalus, Arabic Transparent, Simplified Arabic, Traditional Arabic
1.1496 +Devanagari Mangal
1.1497 +Thai Angsana New, Browallia, Cordia New, DilleniaUPC, EucrosiaUPC,
1.1498 + FreesiaUPC, IrisUPC, JasmineUPC, KodchiangUPC, LilyUPC
1.1499 +HanIdeographs Chinese : SimSun, SimHei (Simplified) / MingLiU (Traditional)
1.1500 + Japanese: MS Mincho, MS Gothic
1.1501 + Korean : Batang, Gulim
1.1502 +*/
1.1503 +const TText* const GlyphSample::KTScript2GlyphSample[] =
1.1504 + {
1.1505 + //
1.1506 + // 02 EScriptLatin
1.1507 + //
1.1508 + // 0x00C0 - Ascent : Capital letter A with grave (Latin-1 Supplement)
1.1509 + // 0x013A - Ascent : Small letter l with acute (Latin Extended A)
1.1510 + // 0x1EA2 - Ascent : Capital letter A with hook above (Latin Extended Additional)
1.1511 + // 0x00C7 - Descent: Capital letter C with cedilla (Latin-1 Supplement)
1.1512 + // 0x0163 - Descent: Small letter t with cedilla (Latin Extended A)
1.1513 + //
1.1514 + _S("\x00C0\x013A\x1EA2\x00C7\x0163"),
1.1515 + //
1.1516 + // 03 EScriptGreek
1.1517 + //
1.1518 + // 0x03AA - Ascent : Capital letter iota with dialytika
1.1519 + // 0x03AB - Ascent : Capital letter upsilon with dialytika
1.1520 + // 0x03AE - Descent: Small letter eta with tonos
1.1521 + // 0x03B2 - Descent: Small letter beta
1.1522 + // 0x03C8 - Descent: Small letter psi
1.1523 + //
1.1524 + _S("\x03AA\x03AB\x03AE\x03B2\x03C8"),
1.1525 + //
1.1526 + // 04 EScriptCyrillic
1.1527 + //
1.1528 + // 0x0403 - Ascent : Capital letter gje
1.1529 + // 0x0419 - Ascent : Capital letter short i
1.1530 + // 0x0440 - Descent: Small letter er
1.1531 + // 0x0452 - Descent: Small letter dje
1.1532 + // 0x0458 - Descent: Small letter je
1.1533 + //
1.1534 + _S("\x0403\x0419\x0440\x0452\x0458"),
1.1535 + //
1.1536 + // 05 EScriptHebrew
1.1537 + //
1.1538 + // 0x05BE - Ascent : Punctuation maqaf
1.1539 + // 0x05DC - Ascent : Letter lamed
1.1540 + // 0x05B0 - Descent: Point sheva
1.1541 + // 0x05BD - Descent: Point meteg
1.1542 + // 0x05E7 - Descent: Letter qof
1.1543 + //
1.1544 + _S("\x05BE\x05DC\x05B0\x05BD\x05E7"),
1.1545 + //
1.1546 + // 06 EScriptArabic
1.1547 + //
1.1548 + // 0x0670 - Ascent : Alef above (Arabic)
1.1549 + // 0x0671 - Ascent : Hamzat Wasl on Alef isolated form
1.1550 + // 0x064D - Descent: Kasratan (Arabic)
1.1551 + // 0xFB7B - Descent: Final form of 0686
1.1552 + // 0xFBF2 - Descent: Final form of 064A
1.1553 + //
1.1554 + //PDEF120737: EScriptArabic value has been changed for this defect & tested using the font file provided by client (i.e. kamelion arabic font).
1.1555 + //The client's font file can't be used for IPR reasons. Thus the test code to demonstrate this defect
1.1556 + //is not added. Also, there was no other font file available that reproduces this defect.
1.1557 + //
1.1558 + _S("\x0670\x0671\x064D\xFB7B\xFBF2"),
1.1559 + //
1.1560 + // 07 EScriptDevanagari
1.1561 + //
1.1562 + // 0x0914 - Ascent : Letter au
1.1563 + // 0x0951 - Ascent : Stress sign udatta
1.1564 + // 0x0941 - Descent: Vowel sign u
1.1565 + // 0x0944 - Descent: Vowel sign rr
1.1566 + // 0x0963 - Descent: Vowel sign vocalic ll
1.1567 + //
1.1568 + _S("\x0914\x0951\x0941\x0944\x0963"),
1.1569 + //
1.1570 + // 08 EScriptThai
1.1571 + //
1.1572 + // 0x0E49 - Ascent : Character mai tho
1.1573 + // 0x0E4B - Ascent : Character mai chattawa
1.1574 + // 0x0E0E - Descent: Character do chada
1.1575 + // 0x0E24 - Descent: Character ru
1.1576 + // 0x0E39 - Descent: Character sara uu
1.1577 + //
1.1578 + _S("\x0E49\x0E4B\x0E0E\x0E24\x0E39"),
1.1579 + //
1.1580 + // 09 EScriptHanIdeographs
1.1581 + //
1.1582 + // 0x1100 - Ascent/Descent: Korean
1.1583 + // 0x4E1C - Ascent/Descent: Chinese Simplified
1.1584 + // 0x5283 - Ascent/Descent: Japanese
1.1585 + // 0x758A - Ascent : Chinese Traditional
1.1586 + // 0x7BEA - Descent: Chinese Traditional
1.1587 + //
1.1588 + _S("\x1100\x4E1C\x5283\x758A\x7BEA"),
1.1589 + };
1.1590 +
1.1591 +/**
1.1592 +Maps a TLanguage type to the TScript type.
1.1593 +@internalTechnology
1.1594 +@param aLanguage The language.
1.1595 +@return A TInt representing the script, or
1.1596 +EScriptNone if its not defined for aLanguage.
1.1597 +*/
1.1598 +EXPORT_C TInt GlyphSample::TLanguage2TScript(TLanguage aLanguage)
1.1599 + {
1.1600 + if (ELangNone == aLanguage || ELangMaximum == aLanguage || aLanguage >= (sizeof(KTLanguage2TScript)/sizeof(KTLanguage2TScript[0])))
1.1601 + {
1.1602 + return EScriptNone;
1.1603 + }
1.1604 + return KTLanguage2TScript[aLanguage];
1.1605 + }
1.1606 +
1.1607 +/**
1.1608 +Maps a TScript type to some glyph samples which are stored as Unicode.
1.1609 +@internalTechnology
1.1610 +@param aScript The script.
1.1611 +@return A TPtrC pointing to the first glyph sample,
1.1612 +or empty if no samples is defined for aScript.
1.1613 +*/
1.1614 +EXPORT_C const TPtrC GlyphSample::TScript2GlyphSample(TInt aScript)
1.1615 + {
1.1616 + if (EScriptOther >= aScript)
1.1617 + {
1.1618 + return TPtrC();
1.1619 + }
1.1620 + // -3 to offset EScriptDefault, EScriptNone and EScriptOther
1.1621 + // being the first three elements in TScript.
1.1622 + return TPtrC(KTScript2GlyphSample[aScript - 3]);
1.1623 + }
1.1624 +
1.1625 +
1.1626 +EXPORT_C RFontTable::RFontTable():iTableContent(0), iLength(0),
1.1627 + iFont(NULL), iTag(0)
1.1628 + {
1.1629 + // a null constructor.
1.1630 + }
1.1631 +
1.1632 +EXPORT_C TInt
1.1633 +RFontTable::Open(CFont& aFont, TUint32 aTag)
1.1634 + {
1.1635 + TGetFontTableParam param;
1.1636 + param.iTag = aTag;
1.1637 +
1.1638 + // remember the parameters, to be used when releasing the font table.
1.1639 + iFont = &aFont;
1.1640 + iTag = aTag;
1.1641 +
1.1642 + TInt ret = aFont.ExtendedFunction(KFontGetFontTable, (TAny *)¶m);
1.1643 + if (KErrNone == ret)
1.1644 + {
1.1645 + iTableContent = (TAny *)param.iContent;
1.1646 + iLength = param.iLength;
1.1647 + }
1.1648 + return ret;
1.1649 + }
1.1650 +
1.1651 +EXPORT_C TInt
1.1652 +RFontTable::TableLength() const
1.1653 + {
1.1654 + return iLength;
1.1655 + }
1.1656 +
1.1657 +EXPORT_C const TUint8*
1.1658 +RFontTable::TableContent() const
1.1659 + {
1.1660 + return (TUint8*)iTableContent;
1.1661 + }
1.1662 +
1.1663 +EXPORT_C void
1.1664 +RFontTable::Close()
1.1665 + {
1.1666 + if (NULL != iFont)
1.1667 + {
1.1668 + (void)iFont->ExtendedFunction(KFontReleaseFontTable, (TAny *)&iTag);
1.1669 + }
1.1670 + iTableContent = 0;
1.1671 + iLength = 0;
1.1672 + iFont = NULL;
1.1673 + iTag = 0;
1.1674 + }
1.1675 +
1.1676 +EXPORT_C
1.1677 +RGlyphOutlineIterator::RGlyphOutlineIterator():iOutlines(0), iLengths(0),
1.1678 + iCursor(-1), iCount(0), iFont(NULL), iCodes(NULL), iHinted(EFalse)
1.1679 + {
1.1680 + // a null constructor.
1.1681 + }
1.1682 +
1.1683 +EXPORT_C TInt
1.1684 +RGlyphOutlineIterator::Open(CFont& aFont, const TUint* aCodes, TInt aCount, TBool aHinted)
1.1685 + {
1.1686 + if (NULL == aCodes || 0 == aCount)
1.1687 + {
1.1688 + return KErrArgument;
1.1689 + }
1.1690 + TGetGlyphOutlineParam param;
1.1691 + iLengths = (TInt *)User::Alloc(sizeof(TInt) * aCount);
1.1692 + if (NULL == iLengths)
1.1693 + {
1.1694 + return KErrNoMemory;
1.1695 + }
1.1696 + iOutlines = (TAny **)User::Alloc(sizeof(TAny *) * aCount);
1.1697 + if (NULL == iOutlines)
1.1698 + {
1.1699 + User::Free(iLengths);
1.1700 + iLengths = NULL;
1.1701 + return KErrNoMemory;
1.1702 + }
1.1703 +
1.1704 + param.iLengths = iLengths;
1.1705 + param.iCount = aCount;
1.1706 + param.iCodes = aCodes;
1.1707 + param.iHinted = aHinted;
1.1708 + param.iOutlines = iOutlines;
1.1709 +
1.1710 + /* information needed in Close() */
1.1711 + iCodes = (TUint *)User::Alloc(sizeof(TUint) * aCount);
1.1712 + if (NULL == iCodes)
1.1713 + {
1.1714 + User::Free(iLengths);
1.1715 + User::Free(iOutlines);
1.1716 + iLengths = NULL;
1.1717 + iOutlines = NULL;
1.1718 + return KErrNoMemory;
1.1719 + }
1.1720 + Mem::Copy(iCodes, aCodes, aCount*sizeof(TUint));
1.1721 + iFont = &aFont;
1.1722 + iHinted = aHinted;
1.1723 + iCount = aCount;
1.1724 +
1.1725 + TInt ret = aFont.ExtendedFunction(KFontGetGlyphOutline, (TAny *)¶m);
1.1726 + if (KErrNone != ret)
1.1727 + {
1.1728 + User::Free(iLengths);
1.1729 + User::Free(iOutlines);
1.1730 + User::Free(iCodes);
1.1731 + iLengths = NULL;
1.1732 + iOutlines = NULL;
1.1733 + iCodes = NULL;
1.1734 + iFont = NULL;
1.1735 + }
1.1736 + else
1.1737 + {
1.1738 + iCursor = 0;
1.1739 + }
1.1740 +
1.1741 + return ret;
1.1742 + }
1.1743 +
1.1744 +EXPORT_C const TUint8*
1.1745 +RGlyphOutlineIterator::Outline() const
1.1746 + {
1.1747 + TEXTBASE_ASSERT_ALWAYS(iCursor >= 0, ETextBasePanic_Unknown);
1.1748 +
1.1749 + if (iLengths[iCursor] < 0)
1.1750 + {
1.1751 + return NULL;
1.1752 + }
1.1753 + else
1.1754 + {
1.1755 + return (const TUint8*)iOutlines[iCursor];
1.1756 + }
1.1757 + }
1.1758 +
1.1759 +EXPORT_C TInt
1.1760 +RGlyphOutlineIterator::OutlineLength() const
1.1761 + {
1.1762 + TEXTBASE_ASSERT_ALWAYS(iCursor >= 0, ETextBasePanic_Unknown);
1.1763 +
1.1764 + if (iLengths[iCursor] < 0)
1.1765 + {
1.1766 + return KErrGeneral;
1.1767 + }
1.1768 + else
1.1769 + {
1.1770 + return iLengths[iCursor];
1.1771 + }
1.1772 + }
1.1773 +
1.1774 +EXPORT_C TInt
1.1775 +RGlyphOutlineIterator::Next()
1.1776 + {
1.1777 + if (iCursor >= 0 && iCursor < iCount-1)
1.1778 + {
1.1779 + ++iCursor;
1.1780 + return KErrNone;
1.1781 + }
1.1782 + else
1.1783 + {
1.1784 + iCursor = -1;
1.1785 + // if the iterator goes beyond the last element [when
1.1786 + // Next() returns KErrNotFound], the next call
1.1787 + // to Outline() or OutlineLength() will panic.
1.1788 +
1.1789 + return KErrNotFound;
1.1790 + }
1.1791 + }
1.1792 +
1.1793 +EXPORT_C void
1.1794 +RGlyphOutlineIterator::Close()
1.1795 + {
1.1796 + TReleaseGlyphOutlineParam param;
1.1797 + param.iCount = iCount;
1.1798 + param.iHinted = iHinted;
1.1799 + param.iCodes = iCodes;
1.1800 +
1.1801 + if (NULL != iFont)
1.1802 + {
1.1803 + iFont->ExtendedFunction(KFontReleaseGlyphOutline, (TAny *)¶m);
1.1804 + }
1.1805 +
1.1806 + iFont = NULL;
1.1807 + iCount = 0;
1.1808 + User::Free(iLengths);
1.1809 + iLengths = NULL;
1.1810 + iCursor = -1;
1.1811 + User::Free(iCodes);
1.1812 + iCodes = NULL;
1.1813 + User::Free(iOutlines);
1.1814 + iOutlines = NULL;
1.1815 + }