svgtopt/SVG/SVGEngine/src/SVGAttributeVerifier.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  SVG Implementation header file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "SVGAttributeVerifier.h"
       
    20 #include <limits.h>
       
    21 #include <hal.h>
       
    22 #include <hal_data.h>
       
    23 // --------------------------------------------------------------------------
       
    24 // TBool CSvgAttributeVerifier::ParseForDecimalValue( const TDesC& aNum2Str, TReal32& aValue )
       
    25 // ---------------------------------------------------------------------------
       
    26 TBool CSvgAttributeVerifier::ParseForDecimalValue( const TDesC& aNum2Str, TReal32& aValue, const TDesC& aAttrValue, TBool isSvgElement )
       
    27 	{
       
    28 	TLex parser( aNum2Str );
       
    29 	parser.SkipSpace();
       
    30 	TInt result = parser.Val( aValue, '.' );
       
    31 	TChar chr;
       
    32     TBool numUnits = EFalse ;
       
    33     TPtrC16 remChars = parser.Remainder();
       
    34     
       
    35     TInt dimInTwips ;
       
    36     TInt dimInPixels;
       
    37     const TReal32 TwipsInCentimeters = 566.929133858268 ;
       
    38     const TReal32 TwipsInInches = 1440 ;
       
    39     const TReal32 TwipsInPt = 20 ;
       
    40     const TReal32 TwipsInPc = 240 ;
       
    41     
       
    42     _LIT(Kcm,"cm");
       
    43     _LIT(Kmm,"mm");
       
    44     _LIT(Kin,"in");
       
    45     _LIT(KPx,"px");
       
    46     _LIT(KPt,"pt");
       
    47     _LIT(KPc,"pc");
       
    48     _LIT(KPer,"%");
       
    49     
       
    50     _LIT(KWidth, "width");
       
    51     _LIT(KHeight, "height");
       
    52     
       
    53     if(isSvgElement)
       
    54     {
       
    55 	    if(aAttrValue == KWidth)
       
    56 	    {
       
    57 	  		if(remChars == Kcm)
       
    58 	    	{
       
    59 		    	numUnits = ETrue;
       
    60 		    	HAL::Get( HALData::EDisplayXTwips, dimInTwips );
       
    61 				HAL::Get( HALData::EDisplayXPixels, dimInPixels );
       
    62 				
       
    63 				aValue *=  (dimInPixels*TwipsInCentimeters)/dimInTwips ;
       
    64 				
       
    65 	    	}
       
    66 		    else if(remChars == Kmm)
       
    67 		    {
       
    68 		    	numUnits = ETrue;
       
    69 		    	HAL::Get( HALData::EDisplayXTwips, dimInTwips );
       
    70 				HAL::Get( HALData::EDisplayXPixels, dimInPixels );
       
    71 				
       
    72 				aValue *=  (dimInPixels*TwipsInCentimeters/10)/dimInTwips ;
       
    73 		    }
       
    74 		    else if(remChars == Kin)
       
    75 		    {
       
    76 		    	numUnits = ETrue;
       
    77 		    	
       
    78 				HAL::Get( HALData::EDisplayXTwips, dimInTwips );
       
    79 				HAL::Get( HALData::EDisplayXPixels, dimInPixels );
       
    80 				aValue *=  (dimInPixels*TwipsInInches)/dimInTwips ;
       
    81 		    }
       
    82 		    else if(remChars == KPt)
       
    83 		    {
       
    84 		    	numUnits = ETrue;
       
    85 		    	
       
    86 				HAL::Get( HALData::EDisplayXTwips, dimInTwips );
       
    87 				HAL::Get( HALData::EDisplayXPixels, dimInPixels );
       
    88 				aValue *=  (dimInPixels*TwipsInPt)/dimInTwips ;
       
    89 		    }
       
    90 		    else if(remChars == KPc)
       
    91 		    {
       
    92 		    	numUnits = ETrue;
       
    93 		    	
       
    94 				HAL::Get( HALData::EDisplayXTwips, dimInTwips );
       
    95 				HAL::Get( HALData::EDisplayXPixels, dimInPixels );
       
    96 				aValue *=  (dimInPixels*TwipsInPc)/dimInTwips ;
       
    97 		    }
       
    98 		    else if(remChars == KPx || remChars == KPer)
       
    99 		    {
       
   100 		    	numUnits = ETrue;
       
   101 		    }
       
   102 		}
       
   103 	    else if(aAttrValue == KHeight)
       
   104 	    {
       
   105 	    	if(remChars == Kcm)
       
   106 	    	{
       
   107 		    	numUnits = ETrue;
       
   108 		    
       
   109 		    	HAL::Get( HALData::EDisplayYTwips, dimInTwips );
       
   110 				HAL::Get( HALData::EDisplayYPixels, dimInPixels );
       
   111 				
       
   112 				aValue *=  (dimInPixels*TwipsInCentimeters)/dimInTwips ;
       
   113 	    	}
       
   114 		    else if(remChars == Kmm)
       
   115 		    {
       
   116 		    	numUnits = ETrue;
       
   117 		    	
       
   118 		    	HAL::Get( HALData::EDisplayYTwips, dimInTwips );
       
   119 				HAL::Get( HALData::EDisplayYPixels, dimInPixels );
       
   120 				
       
   121 				aValue *=  (dimInPixels*TwipsInCentimeters/10)/dimInTwips ;
       
   122 		    }
       
   123 		    else if(remChars == Kin)
       
   124 		    {
       
   125 		    	numUnits = ETrue;
       
   126 		    	
       
   127 				HAL::Get( HALData::EDisplayYTwips, dimInTwips );
       
   128 				HAL::Get( HALData::EDisplayYPixels, dimInPixels );
       
   129 				aValue *=  (dimInPixels*TwipsInInches)/dimInTwips ;
       
   130 		    }
       
   131 		    else if(remChars == KPt)
       
   132 		    {
       
   133 		    	numUnits = ETrue;
       
   134 		    	
       
   135 				HAL::Get( HALData::EDisplayYTwips, dimInTwips );
       
   136 				HAL::Get( HALData::EDisplayYPixels, dimInPixels );
       
   137 				aValue *=  (dimInPixels*TwipsInPt)/dimInTwips ;
       
   138 		    }
       
   139 		    else if(remChars == KPc)
       
   140 		    {
       
   141 		    	numUnits = ETrue;
       
   142 		    	
       
   143 				HAL::Get( HALData::EDisplayYTwips, dimInTwips );
       
   144 				HAL::Get( HALData::EDisplayYPixels, dimInPixels );
       
   145 				aValue *=  (dimInPixels*TwipsInPc)/dimInTwips ;
       
   146 		    }
       
   147 		    else if(remChars == KPx || remChars == KPer)
       
   148 		    {
       
   149 		    	numUnits = ETrue;
       
   150 		    }
       
   151 		}
       
   152     }
       
   153     
       
   154     
       
   155     if(!numUnits)
       
   156 	while(!(parser.Eos()))
       
   157 	{
       
   158 		chr=parser.Get();
       
   159 		if(!chr.IsDigit())
       
   160 		{
       
   161 			aValue=0;
       
   162 			return result==KErrNotFound;	
       
   163 		}
       
   164 		parser.Inc();
       
   165 	}
       
   166 
       
   167 	if (result != KErrNone)
       
   168 		{
       
   169 		aValue= 0;
       
   170 		}
       
   171 	parser.SkipSpace();
       
   172 	return result == KErrNone;
       
   173 	}
       
   174 
       
   175 
       
   176 
       
   177 
       
   178 // --------------------------------------------------------------------------
       
   179 // TBool CSvgAttributeVerifier::ValidAttrValue( const TDesC& aValue,
       
   180 // ---------------------------------------------------------------------------
       
   181 TBool CSvgAttributeVerifier::ValidAttrValue( const TDesC& aValue,
       
   182 											 TReal32& aConvVal,
       
   183 											 TUint8 aDatatype,
       
   184 											 const TDesC& aAttrValue,
       
   185 											 TBool isSvgElement)
       
   186 	{
       
   187 	TReal32 lMinValue = (TReal32)(aDatatype==KSVG_LENGTH_TYPE ? 0 : -KMax16BitValue);
       
   188 	// invalid number string
       
   189 	if ( !ParseForDecimalValue( aValue, aConvVal, aAttrValue, isSvgElement) )
       
   190 		{
       
   191 		aConvVal=0;
       
   192 		return EFalse;
       
   193 		}
       
   194 	// less than minimum value
       
   195 	else if ( aConvVal > KMax16BitValue )
       
   196 		{
       
   197 		aConvVal = KMax16BitValue;
       
   198 		return EFalse;
       
   199 		}
       
   200 	// greater than maximum value
       
   201 	else if ( aConvVal < lMinValue )
       
   202 		{
       
   203 		aConvVal = lMinValue;
       
   204 		return EFalse;
       
   205 		}
       
   206 	// number string is valid and within range
       
   207 	return ETrue;
       
   208 	}
       
   209