Kaydet (Commit) 4c8aa301 authored tarafından Caolán McNamara's avatar Caolán McNamara

advance over font token during font name parsing

Change-Id: I457a4cae7907df6fc05535873ed51766c56220ee
üst 9d491e73
...@@ -169,10 +169,11 @@ class Parser ...@@ -169,10 +169,11 @@ class Parser
void readLink(); void readLink();
void readMaskedImage(); void readMaskedImage();
void readSoftMaskedImage(); void readSoftMaskedImage();
int parseFontCheckForString( const sal_Unicode* pCopy, const char* str, sal_Int32& nLen, sal_Int32 parseFontCheckForString(const sal_Unicode* pCopy, sal_Int32 nCopyLen,
FontAttributes& aResult, bool bItalic, bool bBold); const char* pAttrib, sal_Int32 nAttribLen,
int parseFontRemoveSuffix( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen); FontAttributes& rResult, bool bItalic, bool bBold);
sal_Int32 parseFontRemoveSuffix(const sal_Unicode* pCopy, sal_Int32 nCopyLen,
const char* pAttrib, sal_Int32 nAttribLen);
public: public:
Parser( const ContentSinkSharedPtr& rSink, Parser( const ContentSinkSharedPtr& rSink,
...@@ -459,41 +460,40 @@ rendering::ARGBColor Parser::readColor() ...@@ -459,41 +460,40 @@ rendering::ARGBColor Parser::readColor()
return aRes; return aRes;
} }
int Parser::parseFontCheckForString( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen, sal_Int32 Parser::parseFontCheckForString(
FontAttributes& aResult, bool bItalic, bool bBold) const sal_Unicode* pCopy, sal_Int32 nCopyLen,
const char* pAttrib, sal_Int32 nAttribLen,
FontAttributes& rResult, bool bItalic, bool bBold)
{ {
int l = strlen(s); if (nCopyLen < nAttribLen)
if (nLen < l)
return 0; return 0;
for (int i = 0; i < l; i++) for (sal_Int32 i = 0; i < nAttribLen; ++i)
if (tolower(pCopy[i]) != s[i] if (tolower(pCopy[i]) != pAttrib[i]
&& toupper(pCopy[i]) != s[i]) && toupper(pCopy[i]) != pAttrib[i])
return 0; return 0;
aResult.isItalic = bItalic; rResult.isItalic = bItalic;
aResult.isBold = bBold; rResult.isBold = bBold;
nLen -= l; return nAttribLen;
pCopy += l;
return l;
} }
int Parser::parseFontRemoveSuffix( const sal_Unicode* pCopy, const char* s, sal_Int32& nLen) sal_Int32 Parser::parseFontRemoveSuffix(
const sal_Unicode* pCopy, sal_Int32 nCopyLen,
const char* pAttrib, sal_Int32 nAttribLen)
{ {
int l = strlen(s); if (nCopyLen < nAttribLen)
if (nLen < l)
return 0; return 0;
for (int i = 0; i < l; i++) for (sal_Int32 i = 0; i < nAttribLen; ++i)
if ( pCopy[nLen - l + i] != s[i] ) if ( pCopy[nCopyLen - nAttribLen + i] != pAttrib[i] )
return 0; return 0;
nLen -= l; return nAttribLen;
return l;
} }
void Parser::parseFontFamilyName( FontAttributes& aResult ) void Parser::parseFontFamilyName( FontAttributes& rResult )
{ {
OUStringBuffer aNewFamilyName( aResult.familyName.getLength() ); OUStringBuffer aNewFamilyName( rResult.familyName.getLength() );
const sal_Unicode* pCopy = aResult.familyName.getStr(); const sal_Unicode* pCopy = rResult.familyName.getStr();
sal_Int32 nLen = aResult.familyName.getLength(); sal_Int32 nLen = rResult.familyName.getLength();
// parse out truetype subsets (e.g. BAAAAA+Thorndale) // parse out truetype subsets (e.g. BAAAAA+Thorndale)
if( nLen > 8 && pCopy[6] == sal_Unicode('+') ) if( nLen > 8 && pCopy[6] == sal_Unicode('+') )
{ {
...@@ -503,17 +503,63 @@ void Parser::parseFontFamilyName( FontAttributes& aResult ) ...@@ -503,17 +503,63 @@ void Parser::parseFontFamilyName( FontAttributes& aResult )
while( nLen ) while( nLen )
{ {
if (parseFontRemoveSuffix( pCopy, "PSMT", nLen)) {} if (parseFontRemoveSuffix(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("PSMT")))
else if (parseFontRemoveSuffix( pCopy, "MT", nLen)) {} {
nLen -= RTL_CONSTASCII_LENGTH("PSMT");
if (parseFontCheckForString( pCopy, "Italic", nLen, aResult, true, false)) {} }
else if (parseFontCheckForString( pCopy, "-Bold", nLen, aResult, false, true)) {} else if (parseFontRemoveSuffix(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("MT")))
else if (parseFontCheckForString( pCopy, "Bold", nLen, aResult, false, true)) {} {
else if (parseFontCheckForString( pCopy, "-Roman", nLen, aResult, false, false)) {} nLen -= RTL_CONSTASCII_LENGTH("MT");
else if (parseFontCheckForString( pCopy, "-LightOblique", nLen, aResult, true, false)) {} }
else if (parseFontCheckForString( pCopy, "-BoldOblique", nLen, aResult, true, true)) {}
else if (parseFontCheckForString( pCopy, "-Light", nLen, aResult, false, false)) {} if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("Italic"), rResult, true, false))
else if (parseFontCheckForString( pCopy, "-Reg", nLen, aResult, false, false)) {} {
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("Italic");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Bold"), rResult, false, true))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Bold");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("Bold"), rResult, false, true))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("Bold");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Roman"), rResult, false, false))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Roman");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-LightOblique"), rResult, true, false))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-LightOblique");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-BoldOblique"), rResult, true, true))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-BoldOblique");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Light"), rResult, false, false))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Light");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else if (parseFontCheckForString(pCopy, nLen, RTL_CONSTASCII_STRINGPARAM("-Reg"), rResult, false, false))
{
sal_Int32 nAttribLen = RTL_CONSTASCII_LENGTH("-Reg");
nLen -= nAttribLen;
pCopy += nAttribLen;
}
else else
{ {
if( *pCopy != '-' ) if( *pCopy != '-' )
...@@ -522,7 +568,7 @@ void Parser::parseFontFamilyName( FontAttributes& aResult ) ...@@ -522,7 +568,7 @@ void Parser::parseFontFamilyName( FontAttributes& aResult )
nLen--; nLen--;
} }
} }
aResult.familyName = aNewFamilyName.makeStringAndClear(); rResult.familyName = aNewFamilyName.makeStringAndClear();
} }
void Parser::readFont() void Parser::readFont()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment