float factor = 1.0f;
nscoord emHeight = -1; nscoord normalLineHeight = -1; aRenderingContext->SetFont(font->mFont); nsCOMPtr<nsIFontMetrics> fm; aRenderingContext->GetFontMetrics(*getter_AddRefs(fm)); if (fm) { fm->GetEmHeight(emHeight); fm->GetNormalLineHeight(normalLineHeight); } float factor;
ComputeLineHeight(nsIRenderingContext* aRenderingContext,                  nsIStyleContext* aStyleContext){  NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");  nscoord lineHeight = -1;  const nsStyleText* text = (const nsStyleText*)    aStyleContext->GetStyleData(eStyleStruct_Text);  const nsStyleFont* font = (const nsStyleFont*)    aStyleContext->GetStyleData(eStyleStruct_Font);  nsStyleUnit unit = text->mLineHeight.GetUnit();  if (eStyleUnit_Inherit == unit) {    // Inherit parents line-height value    nsCOMPtr<nsIStyleContext> parentSC =      getter_AddRefs(GetNonInheritedLineHeightStyleContext(aStyleContext));    if (parentSC) {      text = (const nsStyleText*) parentSC->GetStyleData(eStyleStruct_Text);      unit = text->mLineHeight.GetUnit();      if (eStyleUnit_Percent == unit) {        // For percent, we inherit the computed value so update the        // font to use the parent's font not our font.        font = (const nsStyleFont*) parentSC->GetStyleData(eStyleStruct_Font);      }    }  }  if (eStyleUnit_Coord == unit) {    // For length values just use the pre-computed value    lineHeight = text->mLineHeight.GetCoordValue();  }  else {    // For "normal", factor or percentage units the computed value of    // the line-height property is found by multiplying the factor by    // the font's <b>actual</b> height. For "normal" we use a factor    // value of "1.0".    float factor = 1.0f;    if (eStyleUnit_Factor == unit) {      factor = text->mLineHeight.GetFactorValue();    }    else if (eStyleUnit_Percent == unit) {      factor = text->mLineHeight.GetPercentValue();    }    aRenderingContext->SetFont(font->mFont);    nsCOMPtr<nsIFontMetrics> fm;    aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));    if (fm) {      fm->GetHeight(lineHeight);    }    // Note: we normally use the actual font height for computing the    // line-height raw value from the style context. On systems where    // they disagree the actual font height is more appropriate. This    // little hack lets us override that behavior to allow for more    // precise layout in the face of imprecise fonts.    if (nsHTMLReflowState::UseComputedHeight()) {      lineHeight = font->mFont.size;    }    lineHeight = NSToCoordRound(factor * lineHeight);  }  return lineHeight;}