From 8a1fe12a11d6fa36a90b196cfbf5ed43ff28f752 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 4 Jul 2014 11:19:33 +1000 Subject: [PATCH] Bug 1031153 - Move unicode-range descriptor serialization to nsStyleUtil. r=dbaron --- layout/style/nsCSSRules.cpp | 49 +----------------------------------- layout/style/nsStyleUtil.cpp | 46 +++++++++++++++++++++++++++++++++ layout/style/nsStyleUtil.h | 2 ++ 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index ffcadc47983..fb3dca597b2 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -31,7 +31,6 @@ #include "nsStyleUtil.h" #include "mozilla/css/Declaration.h" #include "nsCSSParser.h" -#include "nsPrintfCString.h" #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "StyleRule.h" @@ -1408,52 +1407,6 @@ AppendSerializedFontSrc(const nsCSSValue& src, nsAString & aResult) aResult.Truncate(aResult.Length() - 2); // remove the last comma-space } -// print all characters with at least four hex digits -static void -AppendSerializedUnicodePoint(uint32_t aCode, nsACString &aBuf) -{ - aBuf.Append(nsPrintfCString("%04X", aCode)); -} - -// A unicode-range: descriptor is represented as an array of integers, -// to be interpreted as a sequence of pairs: min max min max ... -// It is in source order. (Possibly it should be sorted and overlaps -// consolidated, but right now we don't do that.) -static void -AppendSerializedUnicodeRange(nsCSSValue const & aValue, - nsAString & aResult) -{ - NS_PRECONDITION(aValue.GetUnit() == eCSSUnit_Null || - aValue.GetUnit() == eCSSUnit_Array, - "improper value unit for unicode-range:"); - aResult.Truncate(); - if (aValue.GetUnit() != eCSSUnit_Array) - return; - - nsCSSValue::Array const & sources = *aValue.GetArrayValue(); - nsAutoCString buf; - - NS_ABORT_IF_FALSE(sources.Count() % 2 == 0, - "odd number of entries in a unicode-range: array"); - - for (uint32_t i = 0; i < sources.Count(); i += 2) { - uint32_t min = sources[i].GetIntValue(); - uint32_t max = sources[i+1].GetIntValue(); - - // We don't try to replicate the U+XX?? notation. - buf.AppendLiteral("U+"); - AppendSerializedUnicodePoint(min, buf); - - if (min != max) { - buf.Append('-'); - AppendSerializedUnicodePoint(max, buf); - } - buf.AppendLiteral(", "); - } - buf.Truncate(buf.Length() - 2); // remove the last comma-space - CopyASCIItoUTF16(buf, aResult); -} - // Mapping from nsCSSFontDesc codes to nsCSSFontFaceStyleDecl fields. nsCSSValue nsCSSFontFaceStyleDecl::* const nsCSSFontFaceStyleDecl::Fields[] = { @@ -1539,7 +1492,7 @@ nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, return NS_OK; case eCSSFontDesc_UnicodeRange: - AppendSerializedUnicodeRange(val, aResult); + nsStyleUtil::AppendUnicodeRange(val, aResult); return NS_OK; case eCSSFontDesc_UNKNOWN: diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index b6226badf25..2a8ac081142 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -13,6 +13,7 @@ #include "nsIContentPolicy.h" #include "nsIContentSecurityPolicy.h" #include "nsIURI.h" +#include "nsPrintfCString.h" using namespace mozilla; @@ -461,6 +462,51 @@ nsStyleUtil::ComputeFunctionalAlternates(const nsCSSValueList* aList, } } +// print all characters with at least four hex digits +static void +AppendSerializedUnicodePoint(uint32_t aCode, nsACString& aBuf) +{ + aBuf.Append(nsPrintfCString("%04X", aCode)); +} + +// A unicode-range: descriptor is represented as an array of integers, +// to be interpreted as a sequence of pairs: min max min max ... +// It is in source order. (Possibly it should be sorted and overlaps +// consolidated, but right now we don't do that.) +/* static */ void +nsStyleUtil::AppendUnicodeRange(const nsCSSValue& aValue, nsAString& aResult) +{ + NS_PRECONDITION(aValue.GetUnit() == eCSSUnit_Null || + aValue.GetUnit() == eCSSUnit_Array, + "improper value unit for unicode-range:"); + aResult.Truncate(); + if (aValue.GetUnit() != eCSSUnit_Array) + return; + + nsCSSValue::Array const & sources = *aValue.GetArrayValue(); + nsAutoCString buf; + + NS_ABORT_IF_FALSE(sources.Count() % 2 == 0, + "odd number of entries in a unicode-range: array"); + + for (uint32_t i = 0; i < sources.Count(); i += 2) { + uint32_t min = sources[i].GetIntValue(); + uint32_t max = sources[i+1].GetIntValue(); + + // We don't try to replicate the U+XX?? notation. + buf.AppendLiteral("U+"); + AppendSerializedUnicodePoint(min, buf); + + if (min != max) { + buf.Append('-'); + AppendSerializedUnicodePoint(max, buf); + } + buf.AppendLiteral(", "); + } + buf.Truncate(buf.Length() - 2); // remove the last comma-space + CopyASCIItoUTF16(buf, aResult); +} + /* static */ float nsStyleUtil::ColorComponentToFloat(uint8_t aAlpha) { diff --git a/layout/style/nsStyleUtil.h b/layout/style/nsStyleUtil.h index 0fddc31a3bc..4481e5483e9 100644 --- a/layout/style/nsStyleUtil.h +++ b/layout/style/nsStyleUtil.h @@ -64,6 +64,8 @@ public: static void AppendFontFeatureSettings(const nsCSSValue& src, nsAString& aResult); + static void AppendUnicodeRange(const nsCSSValue& aValue, nsAString& aResult); + static void AppendCSSNumber(float aNumber, nsAString& aResult) { aResult.AppendFloat(aNumber);