//--------------------------------------
//               PowerUI
//
//        For documentation or 
//    if you have any issues, visit
//        powerUI.kulestar.com
//
//    Copyright  2013 Kulestar Ltd
//          www.kulestar.com
//--------------------------------------

using System;
using InfiniText;
using Css;
using PowerUI;


namespace Css.Units{
	
	/// <summary>
	/// Represents an instance of a font relative unit, e.g. em.
	/// </summary>
	
	public class FontUnit:DecimalUnit{
		
		public FontUnit(){
			// All relative:
			Type=ValueType.RelativeNumber;
		}
		
		/// <summary>Gets the active font face for the given element.</summary>
		protected FontFace GetFontFace(RenderableData context){
			
			return context.computedStyle.FontFamilyX.GetFirstFace();
			
		}
		
		/// <summary>Gets the font size from the given element.</summary>
		protected float GetFontSize(RenderableData context,CssProperty property){
			
			if(property==Css.Properties.FontSize.GlobalProperty){
				
				// Font-size itself. Use parent data here:
				if(context!=null){
					context=context.parentData;
				}
				
			}
			
			if(context==null){
				// Default size:
				return 16f;
			}
			
			return context.computedStyle.FontSizeX;
		}
		
		protected override Value Clone(){
			FontUnit result=new FontUnit();
			result.RawValue=RawValue;
			return result;
		}
		
	}
	
}



