textrendering/textformatting/tbox/LAYEMU.CPP
changeset 24 71313a964664
parent 16 56cd22a7a1cb
child 49 4d76f1414957
equal deleted inserted replaced
21:f2f7b3284356 24:71313a964664
    45 const TInt KMaxProportionOfScreenToScroll = 1000;
    45 const TInt KMaxProportionOfScreenToScroll = 1000;
    46 /** minimum scroll proportions in thousandths. This overrides
    46 /** minimum scroll proportions in thousandths. This overrides
    47  the KNumberOfLinesToKeepVisibleDuringScroll constant.*/
    47  the KNumberOfLinesToKeepVisibleDuringScroll constant.*/
    48 const TInt KMinProportionOfScreenToScroll = 600;
    48 const TInt KMinProportionOfScreenToScroll = 600;
    49 
    49 
    50 /**
       
    51 Tests for a high surrogate.
       
    52 @param a UTF16 value.
       
    53 @return ETrue if argument is a high surrogate.
       
    54 @internalComponent
       
    55 */
       
    56 inline TBool IsHighSurrogate(TText a) { return 0xD800 == (a & 0xFC00); }
       
    57 /**
       
    58 Tests for a low surrogate.
       
    59 @param a UTF16 value.
       
    60 @return ETrue if argument is a high surrogate.
       
    61 @internalComponent
       
    62 */
       
    63 inline TBool IsLowSurrogate(TText a) { return 0xDC00 == (a & 0xFC00); }
       
    64 /**
       
    65 Adds a high surrogate to a low surrogate to create a supplementary character.
       
    66 @param aHigh UTF16 high surrogate.
       
    67 @param aLow UTF16 low surrogate.
       
    68 @return Supplementary character represented by the pair <aHigh, aLow>.
       
    69 @pre aHigh is a high surrogate and aLow is a low surrogate.
       
    70 @internalComponent
       
    71 */
       
    72 inline TChar PairSurrogates(TText aHigh, TText aLow)
       
    73 	{
       
    74 	return ((aHigh - 0xd7f7) << 10) + aLow;
       
    75 	}
       
    76 
    50 
    77 /**
    51 /**
    78 Constructs an iterator over the text referenced by aSource.
    52 Constructs an iterator over the text referenced by aSource.
    79 @param aSource The source of the text to be iterated over.
    53 @param aSource The source of the text to be iterated over.
    80 */
    54 */
   128 	valid surrogate pair or an unpaired surrogate, the surrogate is returned.
   102 	valid surrogate pair or an unpaired surrogate, the surrogate is returned.
   129 */
   103 */
   130 TChar CTextLayout::TUtf32SourceCache::GetUtf32(TInt aIndex)
   104 TChar CTextLayout::TUtf32SourceCache::GetUtf32(TInt aIndex)
   131 	{
   105 	{
   132 	TText code = GetUtf16(aIndex);
   106 	TText code = GetUtf16(aIndex);
   133 	if (IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1)
   107 	if (TChar::IsHighSurrogate(code) && iSource->DocumentLength() < aIndex + 1)
   134 		{
   108 		{
   135 		TText code2 = GetUtf16(aIndex + 1);
   109 		TText code2 = GetUtf16(aIndex + 1);
   136 		if (IsLowSurrogate(code2))
   110 		if (TChar::IsLowSurrogate(code2))
   137 			return PairSurrogates(code, code2);
   111 			return TChar::JoinSurrogate(code, code2);
   138 		}
   112 		}
   139 	return code;
   113 	return code;
   140 	}
   114 	}
   141 
   115 
   142 /** Allocates and constructs a CTextLayout object. By default, the formatting
   116 /** Allocates and constructs a CTextLayout object. By default, the formatting
  1059 			iSource->GetText( r - 1, text, format );
  1033 			iSource->GetText( r - 1, text, format );
  1060 			if ( text.Length() > 1 )
  1034 			if ( text.Length() > 1 )
  1061 				{
  1035 				{
  1062 				TUint highSurrogate = text[0];
  1036 				TUint highSurrogate = text[0];
  1063 				TUint lowSurrogate = text[1];
  1037 				TUint lowSurrogate = text[1];
  1064 				if ( IsHighSurrogate( highSurrogate ) &&
  1038 				if ( TChar::IsHighSurrogate( highSurrogate ) &&
  1065 				     IsLowSurrogate( lowSurrogate ) )
  1039 				        TChar::IsLowSurrogate( lowSurrogate ) )
  1066 					--r;
  1040 					--r;
  1067 				}
  1041 				}
  1068 			}
  1042 			}
  1069 		}
  1043 		}
  1070 
  1044 
  2234 	reformat_param.iParInvalid = iParInvalid;
  2208 	reformat_param.iParInvalid = iParInvalid;
  2235 	switch (aType)
  2209 	switch (aType)
  2236 		{
  2210 		{
  2237 		case EFCharacterInsert:
  2211 		case EFCharacterInsert:
  2238 		case EFParagraphDelimiter:
  2212 		case EFParagraphDelimiter:
       
  2213 			{
  2239 			reformat_param.iStartChar = aCursorPos++;
  2214 			reformat_param.iStartChar = aCursorPos++;
  2240 			reformat_param.iNewLength = 1;
  2215 			reformat_param.iNewLength = 1;
       
  2216 
       
  2217 			// surrogate support
       
  2218 			TPtrC textForSurrogate;
       
  2219 			TTmCharFormat formatForSurrogate;
       
  2220 		
       
  2221 			iSource->GetText(aCursorPos-1, textForSurrogate, formatForSurrogate);
       
  2222 			if ( textForSurrogate.Length() > 1 )
       
  2223 				{
       
  2224 				TUint highSurrogate = textForSurrogate[0];
       
  2225 				TUint lowSurrogate = textForSurrogate[1];
       
  2226 				if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) )
       
  2227 					{
       
  2228 					// if we are inserting a surrogate pair, do not break the pair
       
  2229 					aCursorPos++;
       
  2230 					reformat_param.iNewLength++;
       
  2231 					}
       
  2232 				}
  2241 			break;
  2233 			break;
       
  2234 			}
  2242 		case EFLeftDelete:
  2235 		case EFLeftDelete:
       
  2236 			{
  2243 			reformat_param.iStartChar = --aCursorPos;
  2237 			reformat_param.iStartChar = --aCursorPos;
  2244 			reformat_param.iOldLength = 1;
  2238 			reformat_param.iOldLength = 1;
       
  2239 
       
  2240 			// surrogate support
       
  2241 			TPtrC textForSurrogate;
       
  2242 			TTmCharFormat formatForSurrogate;
       
  2243 		
       
  2244 			if (aCursorPos >= 1)
       
  2245 				{
       
  2246 				iSource->GetText(aCursorPos-1, textForSurrogate, formatForSurrogate);
       
  2247 				if ( textForSurrogate.Length() > 1 )
       
  2248 					{
       
  2249 					TUint highSurrogate = textForSurrogate[0];
       
  2250 					TUint lowSurrogate = textForSurrogate[1];
       
  2251 					if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) )
       
  2252 						{
       
  2253 						// if we are deleting a surrogate pair, do not break the pair
       
  2254 						reformat_param.iStartChar = --aCursorPos;
       
  2255 						reformat_param.iOldLength++;
       
  2256 						}
       
  2257 					}
       
  2258 				}
  2245 			break;
  2259 			break;
       
  2260 			}
  2246 		case EFRightDelete:
  2261 		case EFRightDelete:
       
  2262 			{
  2247 			reformat_param.iStartChar = aCursorPos;
  2263 			reformat_param.iStartChar = aCursorPos;
  2248 			reformat_param.iOldLength = 1;
  2264 			reformat_param.iOldLength = 1;
       
  2265 
       
  2266 			// surrogate support
       
  2267 			TPtrC textForSurrogate;
       
  2268 			TTmCharFormat formatForSurrogate;
       
  2269 		
       
  2270 			iSource->GetText(aCursorPos, textForSurrogate, formatForSurrogate);
       
  2271 			if ( textForSurrogate.Length() > 1 )
       
  2272 				{
       
  2273 				TUint highSurrogate = textForSurrogate[0];
       
  2274 				TUint lowSurrogate = textForSurrogate[1];
       
  2275 				if ( TChar::IsHighSurrogate( highSurrogate ) && TChar::IsLowSurrogate( lowSurrogate ) )
       
  2276 					{
       
  2277 					reformat_param.iOldLength++;
       
  2278 					}
       
  2279 				}
  2249 			break;
  2280 			break;
       
  2281 			}
  2250 		default: break;
  2282 		default: break;
  2251 		}
  2283 		}
  2252 
  2284 
  2253 	// Set up the formatting parameters.
  2285 	// Set up the formatting parameters.
  2254 	TTmFormatParam param;
  2286 	TTmFormatParam param;