示例#1
0
PdfRect PdfPage::CreateStandardPageSize( const EPdfPageSize ePageSize, bool bLandscape )
{
    PdfRect rect;

    switch( ePageSize ) 
    {
        case ePdfPageSize_A0:
            rect.SetWidth( 2384.0 );
            rect.SetHeight( 3370.0 );
            break;

        case ePdfPageSize_A1:
            rect.SetWidth( 1684.0 );
            rect.SetHeight( 2384.0 );
            break;

        case ePdfPageSize_A2:
            rect.SetWidth( 1191.0 );
            rect.SetHeight( 1684.0 );
            break;
            
        case ePdfPageSize_A3:
            rect.SetWidth( 842.0 );
            rect.SetHeight( 1190.0 );
            break;

        case ePdfPageSize_A4:
            rect.SetWidth( 595.0 );
            rect.SetHeight( 842.0 );
            break;

        case ePdfPageSize_A5:
            rect.SetWidth( 420.0 );
            rect.SetHeight( 595.0 );
            break;

        case ePdfPageSize_A6:
            rect.SetWidth( 297.0 );
            rect.SetHeight( 420.0 );
            break;

        case ePdfPageSize_Letter:
            rect.SetWidth( 612.0 );
            rect.SetHeight( 792.0 );
            break;
            
        case ePdfPageSize_Legal:
            rect.SetWidth( 612.0 );
            rect.SetHeight( 1008.0 );
            break;

        case ePdfPageSize_Tabloid:
            rect.SetWidth( 792.0 );
            rect.SetHeight( 1224.0 );
            break;

        default:
            break;
    }

    if( bLandscape ) 
    {
        double dTmp = rect.GetWidth();
        rect.SetWidth ( rect.GetHeight() );
        rect.SetHeight(  dTmp );
    }

    return rect;
}
void PdfTilingPattern::Init( EPdfTilingPatternType eTilingType,
		 double strokeR, double strokeG, double strokeB,
		 bool doFill, double fillR, double fillG, double fillB,
		 double offsetX, double offsetY,
		 PdfImage *pImage)
{
	if (eTilingType == ePdfTilingPatternType_Image && pImage == NULL) {
		PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
	}

	if (eTilingType != ePdfTilingPatternType_Image && pImage != NULL) {
		PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
	}

	PdfRect rRect;
	rRect.SetLeft(0);
	rRect.SetBottom(0);

	if (pImage) {
		rRect.SetWidth(pImage->GetWidth());
		rRect.SetHeight(-pImage->GetHeight());
	} else {
		rRect.SetWidth(8);
		rRect.SetHeight(8);
	}

	PdfVariant var;
   rRect.ToVariant( var );

	this->GetObject()->GetDictionary().AddKey( PdfName("PatternType"), static_cast<pdf_int64>(1L) ); // Tiling pattern
	this->GetObject()->GetDictionary().AddKey( PdfName("PaintType"), static_cast<pdf_int64>(1L) ); // Colored
	this->GetObject()->GetDictionary().AddKey( PdfName("TilingType"), static_cast<pdf_int64>(1L) ); // Constant spacing
	this->GetObject()->GetDictionary().AddKey( PdfName("BBox"), var );
	this->GetObject()->GetDictionary().AddKey( PdfName("XStep"), static_cast<pdf_int64>(rRect.GetWidth()) );
	this->GetObject()->GetDictionary().AddKey( PdfName("YStep"), static_cast<pdf_int64>(rRect.GetHeight()) );
	this->GetObject()->GetDictionary().AddKey( PdfName("Resources"), PdfObject( PdfDictionary() ) );

	if (offsetX < -1e-9 || offsetX > 1e-9 || offsetY < -1e-9 || offsetY > 1e-9) {
		PdfArray array;

		array.push_back (static_cast<pdf_int64>(1));
		array.push_back (static_cast<pdf_int64>(0));
		array.push_back (static_cast<pdf_int64>(0));
		array.push_back (static_cast<pdf_int64>(1));
		array.push_back (offsetX);
		array.push_back (offsetY);

		this->GetObject()->GetDictionary().AddKey( PdfName("Matrix"), array );
	}

   std::ostringstream out;
   out.flags( std::ios_base::fixed );
   out.precision( 1L /* clPainterDefaultPrecision */ );
   PdfLocaleImbue(out);

	if (pImage) {
		AddToResources(pImage->GetIdentifier(), pImage->GetObjectReference(), PdfName("XObject"));

      out << rRect.GetWidth() << " 0 0 "
          << rRect.GetHeight() << " "
          << rRect.GetLeft() << " " 
          << rRect.GetBottom() << " cm" << std::endl;
		out << "/" << pImage->GetIdentifier().GetName() << " Do" << std::endl;
	} else {
		if (doFill) {
			out << fillR << " " << fillG << " " << fillB << " rg" << " ";
			out << rRect.GetLeft() << " " << rRect.GetBottom() << " " << rRect.GetWidth() << " " << rRect.GetHeight() << " re" << " ";
			out << "f" <<  " "; //fill rect
		}

		out << strokeR << " " << strokeG << " " << strokeB << " RG" << " ";
		out << "2 J" << " "; // line capability style
		out << "0.5 w" <<  " "; //line width

		double left, bottom, right, top, whalf, hhalf;
		left = rRect.GetLeft();
		bottom = rRect.GetBottom();
		right = left + rRect.GetWidth();
		top = bottom + rRect.GetHeight();
		whalf = rRect.GetWidth() / 2;
		hhalf = rRect.GetHeight() / 2;

		switch (eTilingType) {
		case ePdfTilingPatternType_BDiagonal:
			out << left          << " " << bottom         << " m " << right         << " " << top            << " l ";
			out << left - whalf  << " " << top - hhalf    << " m " << left + whalf  << " " << top + hhalf    << " l ";
			out << right - whalf << " " << bottom - hhalf << " m " << right + whalf << " " << bottom + hhalf << " l" << std::endl;
			break;
		case ePdfTilingPatternType_Cross:
			out << left          << " " << bottom + hhalf << " m " << right         << " " << bottom + hhalf << " l ";
			out << left + whalf  << " " << bottom         << " m " << left + whalf  << " " << top            << " l" << std::endl;
			break;
		case ePdfTilingPatternType_DiagCross:
			out << left          << " " << bottom         << " m " << right         << " " << top            << " l ";
			out << left          << " " << top            << " m " << right         << " " << bottom         << " l" << std::endl;
			break;
		case ePdfTilingPatternType_FDiagonal:
			out << left          << " " << top            << " m " << right         << " " << bottom         << " l ";
			out << left - whalf  << " " << bottom + hhalf << " m " << left + whalf  << " " << bottom - hhalf << " l ";
			out << right - whalf << " " << top + hhalf    << " m " << right + whalf << " " << top - hhalf    << " l" << std::endl;
			break;
		case ePdfTilingPatternType_Horizontal:
			out << left          << " " << bottom + hhalf << " m " << right         << " " << bottom + hhalf << " l ";
			break;
		case ePdfTilingPatternType_Vertical:
			out << left + whalf  << " " << bottom         << " m " << left + whalf  << " " << top            << " l" << std::endl;
			break;
		case ePdfTilingPatternType_Image:
			/* This is handled above, based on the 'pImage' variable */
		default:
			PODOFO_RAISE_ERROR (ePdfError_InvalidEnumValue);
			break;

		}

		out << "S"; //stroke path
	}

	TVecFilters vecFlate;
	vecFlate.push_back( ePdfFilter_FlateDecode );

	std::string str = out.str();
	PdfMemoryInputStream stream(str.c_str(), str.length());

	this->GetObject()->GetStream()->Set(&stream, vecFlate);
}