From a2eb916c20aea61c35d071d93c95eeb90b43df88 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 22 Sep 2014 10:32:58 +1000 Subject: [PATCH] Bug 1069761 - Move AppendSerializedFontSrc to nsStyleUtil. r=jdaggett --- layout/style/nsCSSRules.cpp | 55 +----------------------------------- layout/style/nsStyleUtil.cpp | 55 ++++++++++++++++++++++++++++++++++++ layout/style/nsStyleUtil.h | 3 ++ 3 files changed, 59 insertions(+), 54 deletions(-) diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 74a3f3c4f86..8c1403a9645 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -1397,59 +1397,6 @@ DOMCI_DATA(CSSNameSpaceRule, css::NameSpaceRule) // nsCSSFontFaceStyleDecl and related routines // -// A src: descriptor is represented as an array value; each entry in -// the array can be eCSSUnit_URL, eCSSUnit_Local_Font, or -// eCSSUnit_Font_Format. Blocks of eCSSUnit_Font_Format may appear -// only after one of the first two. (css3-fonts only contemplates -// annotating URLs with formats, but we handle the general case.) -static void -AppendSerializedFontSrc(const nsCSSValue& src, nsAString & aResult) -{ - NS_PRECONDITION(src.GetUnit() == eCSSUnit_Array, - "improper value unit for src:"); - - const nsCSSValue::Array& sources = *src.GetArrayValue(); - size_t i = 0; - - while (i < sources.Count()) { - nsAutoString formats; - - if (sources[i].GetUnit() == eCSSUnit_URL) { - aResult.AppendLiteral("url("); - nsDependentString url(sources[i].GetOriginalURLValue()); - nsStyleUtil::AppendEscapedCSSString(url, aResult); - aResult.Append(')'); - } else if (sources[i].GetUnit() == eCSSUnit_Local_Font) { - aResult.AppendLiteral("local("); - nsDependentString local(sources[i].GetStringBufferValue()); - nsStyleUtil::AppendEscapedCSSString(local, aResult); - aResult.Append(')'); - } else { - NS_NOTREACHED("entry in src: descriptor with improper unit"); - i++; - continue; - } - - i++; - formats.Truncate(); - while (i < sources.Count() && - sources[i].GetUnit() == eCSSUnit_Font_Format) { - formats.Append('"'); - formats.Append(sources[i].GetStringBufferValue()); - formats.AppendLiteral("\", "); - i++; - } - if (formats.Length() > 0) { - formats.Truncate(formats.Length() - 2); // remove the last comma - aResult.AppendLiteral(" format("); - aResult.Append(formats); - aResult.Append(')'); - } - aResult.AppendLiteral(", "); - } - aResult.Truncate(aResult.Length() - 2); // remove the last comma-space -} - // Mapping from nsCSSFontDesc codes to nsCSSFontFaceStyleDecl fields. nsCSSValue nsCSSFontFaceStyleDecl::* const nsCSSFontFaceStyleDecl::Fields[] = { @@ -1531,7 +1478,7 @@ nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, return NS_OK; case eCSSFontDesc_Src: - AppendSerializedFontSrc(val, aResult); + nsStyleUtil::AppendSerializedFontSrc(val, aResult); return NS_OK; case eCSSFontDesc_UnicodeRange: diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index cc8147657dd..4ea19b0b0f9 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -507,6 +507,61 @@ nsStyleUtil::AppendUnicodeRange(const nsCSSValue& aValue, nsAString& aResult) CopyASCIItoUTF16(buf, aResult); } +/* static */ void +nsStyleUtil::AppendSerializedFontSrc(const nsCSSValue& aValue, + nsAString& aResult) +{ + // A src: descriptor is represented as an array value; each entry in + // the array can be eCSSUnit_URL, eCSSUnit_Local_Font, or + // eCSSUnit_Font_Format. Blocks of eCSSUnit_Font_Format may appear + // only after one of the first two. (css3-fonts only contemplates + // annotating URLs with formats, but we handle the general case.) + + NS_PRECONDITION(aValue.GetUnit() == eCSSUnit_Array, + "improper value unit for src:"); + + const nsCSSValue::Array& sources = *aValue.GetArrayValue(); + size_t i = 0; + + while (i < sources.Count()) { + nsAutoString formats; + + if (sources[i].GetUnit() == eCSSUnit_URL) { + aResult.AppendLiteral("url("); + nsDependentString url(sources[i].GetOriginalURLValue()); + nsStyleUtil::AppendEscapedCSSString(url, aResult); + aResult.Append(')'); + } else if (sources[i].GetUnit() == eCSSUnit_Local_Font) { + aResult.AppendLiteral("local("); + nsDependentString local(sources[i].GetStringBufferValue()); + nsStyleUtil::AppendEscapedCSSString(local, aResult); + aResult.Append(')'); + } else { + NS_NOTREACHED("entry in src: descriptor with improper unit"); + i++; + continue; + } + + i++; + formats.Truncate(); + while (i < sources.Count() && + sources[i].GetUnit() == eCSSUnit_Font_Format) { + formats.Append('"'); + formats.Append(sources[i].GetStringBufferValue()); + formats.AppendLiteral("\", "); + i++; + } + if (formats.Length() > 0) { + formats.Truncate(formats.Length() - 2); // remove the last comma + aResult.AppendLiteral(" format("); + aResult.Append(formats); + aResult.Append(')'); + } + aResult.AppendLiteral(", "); + } + aResult.Truncate(aResult.Length() - 2); // remove the last comma-space +} + /* static */ float nsStyleUtil::ColorComponentToFloat(uint8_t aAlpha) { diff --git a/layout/style/nsStyleUtil.h b/layout/style/nsStyleUtil.h index 2f910163d72..67d945a25a7 100644 --- a/layout/style/nsStyleUtil.h +++ b/layout/style/nsStyleUtil.h @@ -71,6 +71,9 @@ public: aResult.AppendFloat(aNumber); } + static void AppendSerializedFontSrc(const nsCSSValue& aValue, + nsAString& aResult); + // convert bitmask value to keyword name for a functional alternate static void GetFunctionalAlternatesName(int32_t aFeature, nsAString& aFeatureName);