sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "FontArabic.h" sl@0: #include "GDIPANIC.h" sl@0: sl@0: sl@0: // sl@0: // Arabic Presentation Forms. sl@0: // sl@0: sl@0: sl@0: /** sl@0: The contextual forms of each character in the range 0621 - 064A, in sl@0: the order final, initial, medial; followed by the forms of sl@0: the lam-alef ligatures (lam with 0622, 0623, 0625 and 0627); sl@0: followed by the forms of the characters in the range 0671 - 06D3 sl@0: */ sl@0: LOCAL_D const TUint16 TheArabicShapeTable[] = sl@0: { sl@0: // Contextual forms for standard Arabic letters sl@0: 0x621, 0x621, 0x621, // 621 sl@0: 0xfe82, 0x622, 0x622, // 622 sl@0: 0xfe84, 0x623, 0x623, // 623 sl@0: 0xfe86, 0x624, 0x624, // 624 sl@0: 0xfe88, 0x625, 0x625, // 625 sl@0: 0xfe8a, 0xfe8b, 0xfe8c, // 626 sl@0: 0xfe8e, 0x627, 0x627, // 627 sl@0: 0xfe90, 0xfe91, 0xfe92, // 628 sl@0: 0xfe94, 0x629, 0x629, // 629 sl@0: 0xfe96, 0xfe97, 0xfe98, // 62a sl@0: 0xfe9a, 0xfe9b, 0xfe9c, // 62b sl@0: 0xfe9e, 0xfe9f, 0xfea0, // 62c sl@0: 0xfea2, 0xfea3, 0xfea4, // 62d sl@0: 0xfea6, 0xfea7, 0xfea8, // 62e sl@0: 0xfeaa, 0x62f, 0x62f, // 62f sl@0: 0xfeac, 0x630, 0x630, // 630 sl@0: 0xfeae, 0x631, 0x631, // 631 sl@0: 0xfeb0, 0x632, 0x632, // 632 sl@0: 0xfeb2, 0xfeb3, 0xfeb4, // 633 sl@0: 0xfeb6, 0xfeb7, 0xfeb8, // 634 sl@0: 0xfeba, 0xfebb, 0xfebc, // 635 sl@0: 0xfebe, 0xfebf, 0xfec0, // 636 sl@0: 0xfec2, 0xfec3, 0xfec4, // 637 sl@0: 0xfec6, 0xfec7, 0xfec8, // 638 sl@0: 0xfeca, 0xfecb, 0xfecc, // 639 sl@0: 0xfece, 0xfecf, 0xfed0, // 63a sl@0: 0x63b, 0x63b, 0x63b, // placeholder sl@0: 0x63c, 0x63c, 0x63c, // placeholder sl@0: 0x63d, 0x63d, 0x63d, // placeholder sl@0: 0x63e, 0x63e, 0x63e, // placeholder sl@0: 0x63f, 0x63f, 0x63f, // placeholder sl@0: 0x640, 0x640, 0x640, // 640 sl@0: 0xfed2, 0xfed3, 0xfed4, // 641 sl@0: 0xfed6, 0xfed7, 0xfed8, // 642 sl@0: 0xfeda, 0xfedb, 0xfedc, // 643 sl@0: 0xfede, 0xfedf, 0xfee0, // 644 sl@0: 0xfee2, 0xfee3, 0xfee4, // 645 sl@0: 0xfee6, 0xfee7, 0xfee8, // 646 sl@0: 0xfeea, 0xfeeb, 0xfeec, // 647 sl@0: 0xfeee, 0x648, 0x648, // 648 sl@0: 0xfef0, 0xfbe8, 0xfbe9, // 649 sl@0: 0xfef2, 0xfef3, 0xfef4, // 64A sl@0: sl@0: // Contextual forms for lam-alef ligatures sl@0: 0xfef6, 0xfef5, 0xfef5, // 644 + 622 sl@0: 0xfef8, 0xfef7, 0xfef7, // 644 + 623 sl@0: 0xfefa, 0xfef9, 0xfef9, // 644 + 625 sl@0: 0xfefc, 0xfefb, 0xfefb, // 644 + 627 sl@0: sl@0: // Contextual forms for extended Arabic letters for Persian, Urdu, Sindhi, etc. sl@0: 0xfb51, 0x0671, 0x0671, // 671 sl@0: 0x0672, 0x0672, 0x0672, // placeholder sl@0: 0x0673, 0x0673, 0x0673, // placeholder sl@0: 0x0674, 0x0674, 0x0674, // placeholder sl@0: 0x0675, 0x0675, 0x0675, // placeholder sl@0: 0x0676, 0x0676, 0x0676, // placeholder sl@0: 0x0677, 0x0677, 0x0677, // placeholder sl@0: 0x0678, 0x0678, 0x0678, // placeholder sl@0: 0xfb67, 0xfb68, 0xfb69, // 679 sl@0: 0xfb5f, 0xfb60, 0xfb61, // 67a sl@0: 0xfb53, 0xfb54, 0xfb55, // 67b sl@0: 0x067c, 0x067c, 0x067c, // placeholder sl@0: 0x067d, 0x067d, 0x067d, // placeholder sl@0: 0xfb57, 0xfb58, 0xfb59, // 67e sl@0: 0xfb63, 0xfb64, 0xfb65, // 67f sl@0: sl@0: 0xfb5b, 0xfb5c, 0xfb5d, // 680 sl@0: 0x0681, 0x0681, 0x0681, // placeholder sl@0: 0x0682, 0x0682, 0x0682, // placeholder sl@0: 0xfb77, 0xfb78, 0xfb79, // 683 sl@0: 0xfb73, 0xfb74, 0xfb75, // 684 sl@0: 0x0685, 0x0685, 0x0685, // placeholder sl@0: 0xfb7b, 0xfb7c, 0xfb7d, // 686 sl@0: 0xfb7f, 0xfb80, 0xfb81, // 687 sl@0: 0xfb89, 0x0688, 0x0688, // 688 sl@0: 0x0689, 0x0689, 0x0689, // placeholder sl@0: 0x068a, 0x068a, 0x068a, // placeholder sl@0: 0x068b, 0x068b, 0x068b, // placeholder sl@0: 0xfb85, 0x068c, 0x068c, // 68c sl@0: 0xfb83, 0x068d, 0x068d, // 68d sl@0: 0xfb87, 0x068e, 0x068e, // 68e sl@0: 0x068f, 0x068f, 0x068f, // placeholder sl@0: sl@0: 0x0690, 0x0690, 0x0690, // placeholder sl@0: 0xfb8d, 0x0691, 0x0691, // 691 sl@0: 0x0692, 0x0692, 0x0692, // placeholder sl@0: 0x0693, 0x0693, 0x0693, // placeholder sl@0: 0x0694, 0x0694, 0x0694, // placeholder sl@0: 0x0695, 0x0695, 0x0695, // placeholder sl@0: 0x0696, 0x0696, 0x0696, // placeholder sl@0: 0x0697, 0x0697, 0x0697, // placeholder sl@0: 0xfb8b, 0x0698, 0x0698, // 698 sl@0: 0x0699, 0x0699, 0x0699, // placeholder sl@0: 0x069a, 0x069a, 0x069a, // placeholder sl@0: 0x069b, 0x069b, 0x069b, // placeholder sl@0: 0x069c, 0x069c, 0x069c, // placeholder sl@0: 0x069d, 0x069d, 0x069d, // placeholder sl@0: 0x069e, 0x069e, 0x069e, // placeholder sl@0: 0x069f, 0x069f, 0x069f, // placeholder sl@0: sl@0: 0x06a0, 0x06a0, 0x06a0, // placeholder sl@0: 0x06a1, 0x06a1, 0x06a1, // placeholder sl@0: 0x06a2, 0x06a2, 0x06a2, // placeholder sl@0: 0x06a3, 0x06a3, 0x06a3, // placeholder sl@0: 0xfb6b, 0xfb6c, 0xfb6d, // 6a4 sl@0: 0x06a5, 0x06a5, 0x06a5, // placeholder sl@0: 0xfb6f, 0xfb70, 0xfb71, // 6a6 sl@0: 0x06a7, 0x06a7, 0x06a7, // placeholder sl@0: 0x06a8, 0x06a8, 0x06a8, // placeholder sl@0: 0xfb8f, 0xfb90, 0xfb91, // 6a9 sl@0: 0x06aa, 0x06aa, 0x06aa, // 6aa sl@0: 0x06ab, 0x06ab, 0x06ab, // 6ab sl@0: 0x06ac, 0x06ac, 0x06ac, // 6ac sl@0: 0xfbd4, 0xfbd5, 0xfbd6, // 6ad sl@0: 0x06ae, 0x06ae, 0x06ae, // 6ae sl@0: 0xfb93, 0xfb94, 0xfb95, // 6af sl@0: sl@0: 0x06b0, 0x06b0, 0x06b0, // placeholder sl@0: 0xfb9b, 0xfb9c, 0xfb9d, // 6b1 sl@0: 0x06b2, 0x06b2, 0x06b2, // 6b2 sl@0: 0xfb97, 0xfb98, 0xfb99, // 6b3 sl@0: 0x06b4, 0x06b4, 0x06b4, // placeholder sl@0: 0x06b5, 0x06b5, 0x06b5, // placeholder sl@0: 0x06b6, 0x06b6, 0x06b6, // placeholder sl@0: 0x06b7, 0x06b7, 0x06b7, // placeholder sl@0: 0x06b8, 0x06b8, 0x06b8, // placeholder sl@0: 0x06b9, 0x06b9, 0x06b9, // placeholder sl@0: 0xfb9f, 0x06ba, 0x06ba, // 6ba sl@0: 0xfba1, 0xfba2, 0xfba3, // 6bb sl@0: 0x06bc, 0x06bc, 0x06bc, // placeholder sl@0: 0x06bd, 0x06bd, 0x06bd, // placeholder sl@0: 0xfbab, 0xfbac, 0xfbad, // 6be sl@0: 0x06bf, 0x06bf, 0x06bf, // placeholder sl@0: sl@0: 0xfba5, 0x06c0, 0x06c0, // 6c0 sl@0: 0xfba7, 0xfba8, 0xfba9, // 6c1 sl@0: 0x06c2, 0x06c2, 0x06c2, // placeholder sl@0: 0x06c3, 0x06c3, 0x06c3, // placeholder sl@0: 0x06c4, 0x06c4, 0x06c4, // placeholder sl@0: 0xfbe1, 0x06c5, 0x06c5, // 6c5 sl@0: 0xfbda, 0x06c6, 0x06c6, // 6c6 sl@0: 0xfbd8, 0x06c7, 0x06c7, // 6c7 sl@0: 0xfbdc, 0x06c8, 0x06c8, // 6c8 sl@0: 0xfbe3, 0x06c9, 0x06c9, // 6c9 sl@0: 0x06ca, 0x06ca, 0x06ca, // placeholder sl@0: 0xfbdf, 0x06cb, 0x06cb, // 6cb sl@0: 0xfbfd, 0xfbfe, 0xfbff, // 6cc sl@0: 0x06cd, 0x06cd, 0x06cd, // placeholder sl@0: 0x06ce, 0x06ce, 0x06ce, // placeholder sl@0: 0x06cf, 0x06cf, 0x06cf, // placeholder sl@0: sl@0: 0xfbe5, 0xfbe6, 0xfbe7, // 6d0 sl@0: 0x06d1, 0x06d1, 0x06d1, // placeholder sl@0: 0xfbaf, 0x06d2, 0x06d2, // 6d2 sl@0: 0xfbb1, 0x06d3, 0x06d3 // 6d3 sl@0: }; sl@0: sl@0: sl@0: static const int KFinal = 0; sl@0: static const int KInitial = 1; sl@0: static const int KMedial = 2; sl@0: static const int KStandardShapeTableOffset = 0x621; sl@0: static const int KLamAlefShapeTableStart = 0x64B - 0x621; sl@0: static const int KExtendedShapeTableOffset = 0x671 - (0x64f - 0x621); sl@0: sl@0: sl@0: static inline TInt ArabicShapeTableIndex(TInt aCode) sl@0: { sl@0: if (aCode >= 0x621 && aCode <= 0x64a) sl@0: return (aCode - KStandardShapeTableOffset) * 3; sl@0: if (aCode >= 0x671 && aCode <= 0x6d3) sl@0: return (aCode - KExtendedShapeTableOffset) * 3; sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: sl@0: static inline TBool IsArabicPoint(TInt aCode) sl@0: { sl@0: return (aCode >= 0x64B && aCode <= 0x655) || aCode == 0x670; sl@0: } sl@0: sl@0: TInt ConsumeCharsAndDeterminePresentationForm(const TUtf32Iterator& aText, sl@0: TUint aFlags, TInt& aLigaturePortionsRemaining) sl@0: /** sl@0: Get the Arabic or other presentation form, consuming as many characters sl@0: as necessary. This function can cope with text that has already been sl@0: reversed. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: TUint c = aText.Get(); sl@0: TInt index = ArabicShapeTableIndex(c); sl@0: if (index != -1) sl@0: { sl@0: if (aLigaturePortionsRemaining != 0) sl@0: { sl@0: --aLigaturePortionsRemaining; sl@0: GDI_ASSERT_DEBUG(!aText.AtEnd(), EGdiPanic_Invariant); sl@0: return 0xFFFF; sl@0: } sl@0: sl@0: int position = -1; sl@0: sl@0: // Find previous and next character, skipping Arabic points. sl@0: TUtf32Iterator tmpText(aText); sl@0: tmpText.Prev(); sl@0: TUint prev = 0xFFFF; sl@0: while (!tmpText.BeforeStart() && (prev == 0xFFFF || IsArabicPoint(prev))) sl@0: prev = tmpText.GetThenPrev(); sl@0: sl@0: tmpText = aText; sl@0: tmpText.Next(); sl@0: TUint next = 0xFFFF; sl@0: while (!tmpText.AtEnd() && (next == 0xFFFF || IsArabicPoint(next))) sl@0: next = tmpText.GetThenNext(); sl@0: sl@0: TInt possible_lam = (aFlags & CFont::TPositionParam::EFLogicalOrder)? sl@0: c : next; sl@0: TInt possible_alef = (aFlags & CFont::TPositionParam::EFLogicalOrder)? sl@0: next : c; sl@0: sl@0: // Perform lam-alef ligation if necessary. sl@0: if (possible_lam == 0x644 && sl@0: (possible_alef == 0x622 || possible_alef == 0x623 || possible_alef == 0x625 || possible_alef == 0x627)) sl@0: { sl@0: switch(possible_alef) sl@0: { sl@0: case 0x622: sl@0: { sl@0: c = 0xfef5; sl@0: index = KLamAlefShapeTableStart; sl@0: break; sl@0: } sl@0: case 0x623: sl@0: { sl@0: c = 0xfef7; sl@0: index = KLamAlefShapeTableStart + 1; sl@0: break; sl@0: } sl@0: case 0x625: sl@0: { sl@0: c = 0xfef9; sl@0: index = KLamAlefShapeTableStart + 2; sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: c = 0xfefb; sl@0: index = KLamAlefShapeTableStart + 3; sl@0: } sl@0: } sl@0: index *= 3; sl@0: aLigaturePortionsRemaining = 2; sl@0: sl@0: next = 0xFFFF; sl@0: while (!tmpText.AtEnd() && (next == 0xFFFF || IsArabicPoint(next))) sl@0: { sl@0: next = tmpText.Get(); sl@0: tmpText.Next(); sl@0: } sl@0: } sl@0: sl@0: TInt left = (aFlags & CFont::TPositionParam::EFLogicalOrder)? prev : next; sl@0: TInt right = (aFlags & CFont::TPositionParam::EFLogicalOrder)? next : prev; sl@0: sl@0: TBool prefix = FALSE; sl@0: if (left == 0x640 || left == 0x200D) // kashida or Zero-Width Joiner sl@0: prefix = TRUE; sl@0: else sl@0: { sl@0: TInt left_index = ArabicShapeTableIndex(left); sl@0: if (left_index != -1) sl@0: { sl@0: if (static_cast(TheArabicShapeTable[left_index + KInitial]) != left || sl@0: static_cast(TheArabicShapeTable[left_index + KMedial]) != left) sl@0: prefix = TRUE; sl@0: } sl@0: } sl@0: TBool suffix = FALSE; sl@0: if (right == 0x640 || right == 0x200D) // kashida or Zero-Width Joiner sl@0: suffix = TRUE; sl@0: else sl@0: { sl@0: TInt right_index = ArabicShapeTableIndex(right); sl@0: if (right_index != -1) sl@0: { sl@0: if (static_cast(TheArabicShapeTable[right_index + KFinal]) != right || sl@0: static_cast(TheArabicShapeTable[right_index + KMedial]) != right) sl@0: suffix = TRUE; sl@0: } sl@0: } sl@0: TBool medial = static_cast(TheArabicShapeTable[index + KMedial]) != c; sl@0: if (medial) sl@0: { sl@0: if (prefix && suffix) sl@0: position = KMedial; sl@0: else if (prefix) sl@0: position = KFinal; sl@0: else if (suffix) sl@0: position = KInitial; sl@0: } sl@0: else sl@0: { sl@0: if (prefix) sl@0: position = KFinal; sl@0: else if (suffix) sl@0: position = KInitial; sl@0: } sl@0: if (position >= 0) sl@0: c = TheArabicShapeTable[index + position]; sl@0: } sl@0: sl@0: return c; sl@0: } sl@0: sl@0: sl@0: // sl@0: // sl@0: // GlyphSelector_Arabic Class definition sl@0: // sl@0: // sl@0: sl@0: TBool GlyphSelector_Arabic::Process(TGlyphSelectionState& aGss, RShapeInfo&) sl@0: { sl@0: // Select glyph - use presentation form if applicable. sl@0: TInt ligaturePortions = aGss.iLigaturePortionsRemaining; sl@0: TUint flags = aGss.iParam.iFlags; sl@0: TUint code = ConsumeCharsAndDeterminePresentationForm(aGss.iText, sl@0: flags, ligaturePortions); sl@0: sl@0: aGss.iText.Next(); sl@0: aGss.iClusterState = !aGss.iText.AtEnd() && sl@0: (aGss.iText.Get().GetCategory() & 0xF0) == TChar::EMarkGroup? sl@0: TGlyphSelectionState::EGClusterNotComplete sl@0: : TGlyphSelectionState::EGClusterComplete; sl@0: sl@0: // If we are beginning a new portion of a ligature, we must set the state. sl@0: if (ligaturePortions != aGss.iLigaturePortionsRemaining) sl@0: { sl@0: if (ligaturePortions != 1) sl@0: aGss.iClusterState = TGlyphSelectionState::EGClusterNotComplete; sl@0: aGss.iLigaturePortionFirstMark = aGss.iParam.iOutputGlyphs; sl@0: if (ligaturePortions < aGss.iLigaturePortionsRemaining) sl@0: { sl@0: aGss.iLigaturePortionsRemaining = ligaturePortions; sl@0: // We have just swallowed a non-initial part of the ligature, which sl@0: // must not be drawn. sl@0: GDI_ASSERT_DEBUG(code == 0xFFFF, EGdiPanic_Invariant); sl@0: return ETrue; sl@0: } sl@0: aGss.iLigaturePortionsRemaining = ligaturePortions; sl@0: } sl@0: sl@0: // In this method we always output the glyph code calculate previously. sl@0: if (!aGss.AppendGlyphToCluster(code)) sl@0: return EFalse; sl@0: sl@0: if (!aGss.IsCombiningClass()) sl@0: { sl@0: aGss.iPen = TGlyphSelectionState::EPenAdvance_Yes; sl@0: return ETrue; sl@0: } sl@0: sl@0: // Adjust glyph's bounds further to position this character. sl@0: aGss.iPen = TGlyphSelectionState::EPenAdvance_No; sl@0: TRect baseBounds = aGss.iParam.iOutput[0].iBounds; sl@0: TInt firstMark = 1; sl@0: if (aGss.iLigaturePortionsRemaining != 0) sl@0: { sl@0: TInt centre = (baseBounds.iBr.iX + baseBounds.iTl.iX) >> 1; sl@0: TBool firstHalf = aGss.iLigaturePortionsRemaining == 2; sl@0: TBool rightHandSide = flags & CFont::TPositionParam::EFLogicalOrder? sl@0: firstHalf : !firstHalf; sl@0: if (rightHandSide) sl@0: baseBounds.iTl.iX = centre; sl@0: else sl@0: baseBounds.iBr.iX = centre; sl@0: if (firstHalf) sl@0: aGss.iClusterState = TGlyphSelectionState::EGClusterNotComplete; sl@0: firstMark = aGss.iLigaturePortionFirstMark; sl@0: } sl@0: aGss.CombineLastGlyphToBase(baseBounds, firstMark); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: TBool GlyphSelector_Arabic::CharactersJoin(TInt aLeftCharacter, TInt aRightCharacter) sl@0: { sl@0: // All the characters join to the right, so we don't need to look them up. sl@0: // as long as they are there at all, it is OK. sl@0: TBool leftIsFixedJoiner = aLeftCharacter == 0x640 || aLeftCharacter == 0x200D; sl@0: if (!leftIsFixedJoiner) sl@0: { sl@0: TInt leftIndex = ArabicShapeTableIndex(aLeftCharacter); sl@0: if (leftIndex == -1) sl@0: return EFalse; sl@0: if (static_cast(TheArabicShapeTable[leftIndex + KFinal]) sl@0: == aLeftCharacter) sl@0: return EFalse; sl@0: } sl@0: if (aRightCharacter == 0x640 || aRightCharacter == 0x200D) sl@0: return !leftIsFixedJoiner; sl@0: TInt rightIndex = ArabicShapeTableIndex(aRightCharacter); sl@0: return rightIndex != -1 sl@0: && static_cast(TheArabicShapeTable[rightIndex + KInitial]) sl@0: != aRightCharacter; sl@0: } sl@0: