DWF

Reply
Active Member
reterVision
Posts: 10
Registered: ‎10-10-2011
Message 1 of 1 (376 Views)

Write W2D problem with multi-page DWF

376 Views, 0 Replies
02-19-2012 08:19 PM

Hi,

 

I've met a problem when I trying to write w2d into multi-page DWF files. 

 

Every time when I called DWFToolkit::smileyvery-happy:WF6PackageWriter::write(), the program just paused and never wake up again. But everything goeswell when I run the same program with one-page DWF.

 

Any suggestiones were appreciated, thank you!

 

Here is my code:

 

DWFToolkit::smileyvery-happy:WFManifest::smileyfrustrated:ectionIterator* piSections = rManifestIn.getSections();
if (piSections)
{
DWFToolkit::smileyvery-happy:WFSection* pSection = NULL;
for (; piSections->valid(); piSections->next())
{
pSection = piSections->get();
pSection->readDescriptor();

if (pSection->type() == _DWF_FORMAT_EPLOT_TYPE_WIDE_STRING) // 2D Model handler.
{
// Add WT_Text.
for (DWFToolkit::smileyvery-happy:WFResourceContainer::ResourceIterator* pResources =
pSection->findResourcesByRole(DWFXML::kzRole_Graphics2d);
pResources && pResources->valid();
pResources->next())
{
if(pResources && pResources->valid())
{
DWFToolkit::smileyvery-happy:WFGraphicResource* w2dGraphics = (DWFToolkit::smileyvery-happy:WFGraphicResource*) pResources->get();
WT_Result res = WT_Result::smileyfrustrated:uccess;

// assumes above call to valid will return false if get()
// would return null
g_pDWFInputStream = pResources->get()->getInputStream();

WT_File inputStream;
inputStream.set_stream_open_action (&DWFInputStreamOpen);
inputStream.set_stream_close_action(&DWFInputStreamClose);
inputStream.set_stream_read_action (&DWFInputStreamRead);
inputStream.set_stream_seek_action (&DWFInputStreamSeek);
inputStream.set_stream_end_seek_action (&DWFInputStreamEndSeek);

// Open file to insert new object.
inputStream.set_file_mode(WT_File::File_Read);
inputStream.open();

// Create temporary w2d file.
WT_File pOutput;
pOutput.set_filename("temp.w2d");
pOutput.set_file_mode (WT_File::File_Write);
pOutput.open();
pOutput.heuristics().set_allow_binary_data(inputStream.heuristics().allow_binary_data());
pOutput.heuristics().set_allow_data_compression(inputStream.heuristics().allow_data_compression());
pOutput.heuristics().set_target_version(inputStream.heuristics().target_version());

double viewHeight=0.0f, viewWidth=0.0f;

while(res == WT_Result::smileyfrustrated:uccess)
{
res = inputStream.process_next_object();
if(res == WT_Result::smileyfrustrated:uccess)
{
const WT_Object* pObj = inputStream.current_object();
if(pObj)
{
switch (pObj->object_id())
{
case WT_Object::smileyvery-happy:WF_Header_ID:
case WT_Object::End_Of_DWF_ID:
// do nothing
break;

case WT_Object::View_ID:
{
WT_View *viewObj = (WT_View *) pObj;
WT_Logical_Box viewBox = viewObj->view();

viewHeight = viewBox.maxpt().m_y - viewBox.minpt().m_y;
viewWidth = viewBox.maxpt().m_x - viewBox.minpt().m_x;
}

default:
pObj->serialize(pOutput);
break;
}
}
}
}

// Close file stream.
inputStream.close();

// Open temporary file for writing new WT_Text.
WT_W2D_Class_Factory cf;
int x=viewWidth-viewWidth/10, y=viewHeight*2/3;

//Create text with overscoring, underscoring, and a bounding box
char contentASCii[255];
wcstombs(contentASCii, comment, wcslen(comment)+1);

// Set font property.
pOutput.desired_rendition().color().set(pOutput.desired_rendition().color_map().map(0));
pOutput.desired_rendition().font().font_name().set("Times New Roman");
pOutput.desired_rendition().font().height() = (WT_Integer32)(2.0 * 70);
pOutput.desired_rendition().font().width_scale() = 822;

// Font rotation.
const double degree = (int)(65636/360);
pOutput.desired_rendition().font().rotation().set((int)(degree * 45.0f));

WT_Text watermarkText = WT_Text(WT_Logical_Point(x+700, y-200), contentASCii);
//Serialize it.
WD_CHECK(watermarkText.serialize(pOutput));

// Add temporary w2d to resources.
pOutput.close();

//
// define the resource - this must be allocated on the heap
//
DWFToolkit::smileyvery-happy:WFGraphicResource* p2Dgfx =
DWFCORE_ALLOC_OBJECT(DWFToolkit::smileyvery-happy:WFGraphicResource(
w2dGraphics->title(), // title
DWFXML::kzRole_Graphics2d, // role
DWFMIME::kzMIMEType_W2D, // MIME type
w2dGraphics->author(), // author
w2dGraphics->description(), // description
w2dGraphics->creationTime(), // creation time
w2dGraphics->modificationTime())); // modification time
if (p2Dgfx == NULL)
{
_DWFCORE_THROW( DWFMemoryException, L"Failed to allocate resource" );
}

p2Dgfx->configureGraphic(
w2dGraphics->transform(),//(const double*)anTransform,
w2dGraphics->extents(),
w2dGraphics->clip()
);
//pSection->removeResource(*w2dGraphics, true);

DWFFile oW2DFilename(L"temp.w2d");
DWFStreamFileDescriptor* pW2DFile = DWFCORE_ALLOC_OBJECT(DWFStreamFileDescriptor(oW2DFilename, L"rb"));
DWFFileInputStream* pW2DFilestream = DWFCORE_ALLOC_OBJECT(DWFFileInputStream);

pW2DFile->open();
pW2DFilestream->attach(pW2DFile, true);
p2Dgfx->setInputStream(pW2DFilestream);
pSection->addResource(p2Dgfx, true);

// Add image to page
DWFToolkit::smileyvery-happy:WFImageResource* pImage =
DWFCORE_ALLOC_OBJECT(DWFToolkit::smileyvery-happy:WFImageResource(L"Watermark",
DWFXML::kzRole_RasterOverlay,
DWFMIME::kzMIMEType_JPG));
if (pImage == NULL)
{
_DWFCORE_THROW( DWFMemoryException, L"Failed to allocate resource" );
}

double anTransform2[4][4] = {
0.02, 0, 0, 0,
0, 0.02, 0, 0,
0, 0, 0.02, 0,
750, 400, 0, 1
};
double anExtents2[4] = {0, 0, 0, 0};
pImage->configureGraphic((const double*)anTransform2,
(const double*)anExtents2, NULL, true, 0, 0);

DWFFile oImageFilename(image_filename);
DWFStreamFileDescriptor* pImageFile = DWFCORE_ALLOC_OBJECT(DWFStreamFileDescriptor(oImageFilename, L"rb"));
DWFFileInputStream* pImageFilestream = DWFCORE_ALLOC_OBJECT(DWFFileInputStream);
pImageFile->open();
pImageFilestream->attach(pImageFile, true);
pImage->setInputStream(pImageFilestream);

// Add image resource into file.
pSection->addResource(pImage, true, true, true, NULL);
pResources->next();
}
}
}
oWriter.addSection(pSection);
}

DWFCORE_FREE_OBJECT(piSections);
}

oWriter.write();

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!