Example #1
0
PDictionary ReadPdfTrailerSection( MappedFile const & f, XrefTable & objmap, char const * xref )
{
	if (::memcmp(xref, "xref", 4 ) == 0 )
	{
		xref = objmap.ReadXrefSection( xref );
		if( !xref )
			// Bogus xref section
			return PDictionary();
	}

	const char * p = GetPdfNextLine( f, xref );

	PObject trailerDictP = ParseDirect( p, objmap );

	PDictionary trailerDict = boost::shared_dynamic_cast<Dictionary>( trailerDictP );
	PStream xrefStream = boost::shared_dynamic_cast< Stream >( trailerDictP );

	if( xrefStream )
		trailerDict = xrefStream->dict;

	assert( trailerDict && "Invalid Trailer Dictionary" );

	PName type = trailerDict->Get<Name>( "Type", objmap );
	if( type && type->str == String( "XRef" ) )
	{
		// xref stream
		if( !xrefStream )
		{
			assert( !"bogus xref stream" );
			return PDictionary();
		}

		xrefStreams.push_back( xrefStream );
		size_t streamLength;
		const char* streamContent = xrefStream->GetStreamBytes( XrefTable( f ), &streamLength );
		objmap.ReadXrefStream( xrefStream, streamContent, streamLength );
	}

	WalkPreviousFileVersions( f, objmap, trailerDict );
	return trailerDict;
}
Example #2
0
bool Style::Parse(const char* t, size_t maxLen, Doc* doc) {
// "background: #8f8; width: 100%; height: 100%;"
#define TSTART (t + startv)
#define TLEN (i - startv)
	size_t startk = -1;
	size_t eq     = -1;
	size_t startv = -1;
	int    nerror = 0;
	for (size_t i = 0; true; i++) {
		bool eof = t[i] == 0 || i == maxLen;
		if (t[i] == 32) {
		} else if (t[i] == ':')
			eq = i;
		else if (t[i] == ';' || (eof && startv != -1)) {
			// clang-format off
			bool ok = true;
			if (MATCH(t, startk, eq, "background"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Color::Parse, CatBackground, *this); }
			else if (MATCH(t, startk, eq, "color"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Color::Parse, CatColor, *this); }
			else if (MATCH(t, startk, eq, "width"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatWidth, *this); }
			else if (MATCH(t, startk, eq, "height"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatHeight, *this); }
			else if (MATCH(t, startk, eq, "padding"))		            { ok = ParseCompound(TSTART, TLEN, &StyleBox::Parse, CatPadding_Left, *this); }
			else if (MATCH(t, startk, eq, "margin"))		            { ok = ParseCompound(TSTART, TLEN, &StyleBox::Parse, CatMargin_Left, *this); }
			else if (MATCH(t, startk, eq, "display"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &ParseDisplayType, CatDisplay, *this); }
			else if (MATCH(t, startk, eq, "position"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &ParsePositionType, CatPosition, *this); }
			else if (MATCH(t, startk, eq, "border"))		            { ok = ParseDirect(TSTART, TLEN, &ParseBorder, *this); }
			else if (MATCH(t, startk, eq, "border-radius"))		        { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatBorderRadius, *this); }
			//else if ( MATCH(t, startk, eq, "left") )                  { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatLeft, *this ); }
			//else if ( MATCH(t, startk, eq, "right") )                 { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatRight, *this ); }
			//else if ( MATCH(t, startk, eq, "top") )                   { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatTop, *this ); }
			//else if ( MATCH(t, startk, eq, "bottom") )                { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatBottom, *this ); }
			else if (MATCH(t, startk, eq, "break"))                     { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBreakType, CatBreak, *this); }
			else if (MATCH(t, startk, eq, "canfocus"))                  { ok = ParseBool(TSTART, TLEN, CatCanFocus, *this); }
			else if (MATCH(t, startk, eq, "cursor"))                    { ok = ParseSingleAttrib(TSTART, TLEN, &ParseCursor, CatCursor, *this); }
			else if (MATCH(t, startk, eq, "flow-context"))              { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowContext, CatFlowContext, *this); }
			else if (MATCH(t, startk, eq, "flow-axis"))                 { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowAxis, CatFlowAxis, *this); }
			else if (MATCH(t, startk, eq, "flow-direction-horizontal")) { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowDirection, CatFlowDirection_Horizontal, *this); }
			else if (MATCH(t, startk, eq, "flow-direction-vertical"))   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowDirection, CatFlowDirection_Vertical, *this); }
			else if (MATCH(t, startk, eq, "box-sizing"))                { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBoxSize, CatBoxSizing, *this); }
			else if (MATCH(t, startk, eq, "font-size"))                 { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatFontSize, *this); }
			else if (MATCH(t, startk, eq, "font-family"))               { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFontFamily, CatFontFamily, *this); }
			else if (MATCH(t, startk, eq, "text-align-vertical"))       { ok = ParseSingleAttrib(TSTART, TLEN, &ParseTextAlignVertical, CatText_Align_Vertical, *this); }
			else if (MATCH(t, startk, eq, "left"))                      { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatLeft, *this); }
			else if (MATCH(t, startk, eq, "hcenter"))                   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatHCenter, *this); }
			else if (MATCH(t, startk, eq, "right"))                     { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatRight, *this); }
			else if (MATCH(t, startk, eq, "top"))                       { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatTop, *this); }
			else if (MATCH(t, startk, eq, "vcenter"))                   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatVCenter, *this); }
			else if (MATCH(t, startk, eq, "bottom"))                    { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatBottom, *this); }
			else if (MATCH(t, startk, eq, "baseline"))                  { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatBaseline, *this); }
			else if (MATCH(t, startk, eq, "bump"))                      { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBump, CatBump, *this); }
			// clang-format on
			else {
				ok = false;
				ParseFail("Parse failed - unknown property: '%.*s'\n", int(eq - startk), t + startk);
			}
			if (!ok)
				nerror++;
			eq     = -1;
			startk = -1;
			startv = -1;
		} else {
			if (startk == -1)
				startk = i;
			else if (startv == -1 && eq != -1)
				startv = i;
		}

		if (eof)
			break;
	}
	return nerror == 0;
#undef TSTART
#undef TLEN
}