void FindPath(PathFinder* pf) { //printf("(%d, %d) -> (%d, %d)\t", pf->startx, pf->starty, pf->endx, pf->endy); for (int i = 0; i < pf->map->width; i++) { for (int e = 0; e < pf->map->height; e++) { pf->nodeMap[i][e].f = 0; pf->nodeMap[i][e].g = 0; pf->nodeMap[i][e].h = 0; pf->nodeMap[i][e].open = NoList; pf->nodeMap[i][e].parent = NULL; } } DeleteQueue(pf->openList); pf->openList = CreateQueue(nodeMinCompare, pf->map->width * pf->map->height); int x = pf->startx; int y = pf->starty; // Step 1: Add starting node to the open list. AddOpen(pf, x, y, NULL); // Step 2: Repeat // If there's nothing in the open list anymore or we arrive at the destination, stop while (GetQueueSize(pf->openList) > 0) { //printf("%d ", GetQueueSize(pf->openList)); // a) Look for the lowest F cost square on the open list. Node* current = (Node*)QueueRemove(pf->openList); x = current->x; y = current->y; // b) Switch it to the closed list. current->open = OnClosedList; // c) For each of the 8 squares adjacent to this current square, attempt to add it // to the open list. // AddOpen checks for adjacent-validity and whether the node is a wall or not. AddOpen(pf, x - 0, y - 1, current); AddOpen(pf, x - 0, y + 1, current); AddOpen(pf, x - 1, y - 0, current); AddOpen(pf, x + 1, y - 0, current); // Diagonal Check if (pf->allowDiagonal) { AddOpen(pf, x - 1, y - 1, current); AddOpen(pf, x + 1, y - 1, current); AddOpen(pf, x - 1, y + 1, current); AddOpen(pf, x + 1, y + 1, current); } // Are we done? if (x == pf->endx && y == pf->endy && pf->nodeMap[pf->endx][pf->endy].open == OnClosedList) { // Step 3: Save Path DeletePath(pf); SavePath(pf, current); /* PathNode* p = pf->path; if (p == NULL) printf(" No Path?"); while (p) { printf("(%p) %d, %d", p, p->x, p->y); p = p->parent; } */ break; } } printf("Pathfinding done\n"); }
void CPDFExport::SaveObjectFrame(LPDFLib::IPDFEContent* pContent, IPDObjectFrame* pdframe, IPDMatrix* matpdf, RectD pageRect) { CComQIPtr<IPDObjectTransformable> pdxframe = pdframe; RectD bounds; pdxframe->getScreenBBox(&bounds); if ( (bounds.X < pageRect.X+pageRect.Width) && (bounds.X+bounds.Width > pageRect.X)) { CComPtr<IPDPath> pdpath; pdframe->get_path(&pdpath); CComQIPtr<IPDObjectWithAppearanceAndStrokeFill> strokefill = pdframe; CComPtr<IObjectMap> subobjects; strokefill->get_subObjects(&subobjects); long nsubobjects; subobjects->get_length(&nsubobjects); //bool bSimple = true; CComQIPtr<IPDObjectFill> fill; CComQIPtr<IPDObjectStroke> stroke; for (int i = 0; i < nsubobjects; i++) { CComPtr<IPDObjectWithBrush> withBrush; subobjects->item(i, (IUnknown**)&withBrush); PDObjectType objectType; withBrush->get_objectType(&objectType); CComPtr<IPDBrush> brush; withBrush->get_brush(&brush); if (i == 0 && objectType == PATH_FILL) fill = withBrush; else if (i == 1 && objectType == PATH_STROKE) stroke = withBrush; } #if 0 if (bSimple) { CComPtr<ISVGPathElement> pathElement; m_svgdoc->createElement(L"path", (IDOMElement**)&pathElement); CComQIPtr<ISVGAnimatedPathData> pathdata = pathElement; CComPtr<ISVGPathSegList> seglist; pathdata->get_normalizedPathSegList(&seglist); SavePath(pdpath, pathElement, seglist); CComQIPtr<ISVGStylable> stylable = pathElement; CComPtr<IDOMCSSStyleDeclaration> style; stylable->get_style(&style); { CComPtr<IPDBrush> brush; fill->get_brush(&brush); CComPtr<IPDColor> color; brush->get_tintedRGBColor(&color); double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); //CComPtr<ISVGPaint> paint; //style->getPropertyCSSValue(L"fill", (ICSSValue**)&paint); WCHAR buf[64]; swprintf(buf, L"#%2.2X%2.2X%2.2X", (int)red, (int)green, (int)blue); //paint->setPaint(SVG_PAINTTYPE_RGBCOLOR, NULL, buf, NULL); style->setProperty(L"fill", buf, L""); } group->appendChild(pathElement, NULL); } else { } #endif LPDFLib::IPDFEPathPtr pPath = m_pdfdoc->CreatePath();// = new CPDFEPath; SavePath(pPath, pdpath, matpdf, pageRect); // Matrix // CComPtr<IPDMatrix> omat0; pdxframe->get_transformMatrix(&omat0); CComPtr<IPDMatrix> omat; omat0->multiply(matpdf, &omat); // LPDFLib::IPDFEMatrixPtr asmat = m_pdfdoc->CreateMatrix(); double a; omat->get_a(&a); asmat->a = a; double b; omat->get_b(&b); asmat->b = b; double c; omat->get_c(&c); asmat->c = c; double d; omat->get_d(&d); asmat->d = d; double e; omat->get_e(&e); asmat->e = e; double f; omat->get_f(&f); asmat->f = f; pPath->SetMatrix(asmat); // Stroke/Fill pPath->SetPaintOp(kPDFEStroke | kPDFEFill); // Graphic state CComQIPtr<IPDStrokeSettings> stroke2 = stroke; //LPDFLib::IPDFEExtGStatePtr extGState; LPDFLib::IPDFEGraphicStatePtr gstate = pPath->GetGState(); double lineWidth; stroke2->get_strokeWeight(&lineWidth); gstate->lineWidth = lineWidth; // stroke2->get_strokeCap(&gstate.lineCap); // stroke2->get_strokeJoin(&gstate.lineJoin); // stroke2->get_strokeMiterLimit(&gstate.miterLimit); // Color #if 0 { // Stroke if (stroke) { CComPtr<IPDBrush> brush; stroke->get_brush(&brush); CComPtr<IPDColor> color; brush->get_tintedRGBColor(&color); double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); gstate.strokeColorSpec.value.color[0] = red/255; gstate.strokeColorSpec.value.color[1] = green/255; gstate.strokeColorSpec.value.color[2] = blue/255; } // Fill if (fill) { CComPtr<IPDBrush> brush; fill->get_brush(&brush); CComPtr<IPDColor> color; brush->get_tintedRGBColor(&color); double red; color->getChannel(0, &red); double green; color->getChannel(1, &green); double blue; color->getChannel(2, &blue); gstate.fillColorSpec.value.color[0] = red/255; gstate.fillColorSpec.value.color[1] = green/255; gstate.fillColorSpec.value.color[2] = blue/255; } } #endif #if 0 CPDFEExtGState* pExtGState = new CPDFEExtGState; { LPDFLib::IPDFCosDictPtr pExtGStateDict = m_pdfdoc->GetCosDoc()->CosNewDict(VARIANT_TRUE); LPDFLib::IPDFCosNamePtr pType = m_pdfdoc->GetCosDoc()->CosNewName(VARIANT_FALSE, L"ExtGState"); pExtGStateDict->CosDictPut(L"Type", pType); LPDFLib::IPDFCosBooleanPtr pAIS = m_pdfdoc->GetCosDoc()->CosNewBoolean(VARIANT_FALSE, false); pExtGStateDict->CosDictPut("AIS", pAIS); pExtGState->Create(pExtGStateDict); pExtGState->SetOpacityStroke(0.5); } gstate.extGState = pExtGState; #endif pPath->SetGState(gstate); // pContent->AddElem(pContent->GetNumElems()-1, pPath); // insert at end // Frame content CComPtr<IPDObject> content; pdframe->get_content(&content); if (content) { PDObjectType objectType; content->get_objectType(&objectType); if (objectType == CONTENT_TEXT) { CComQIPtr<IPDContentText> contentText = content; SaveObjectContentText(pContent, contentText, matpdf, pageRect); } else if (objectType == CONTENT_GRAPHIC) { CComQIPtr<IPDContentGraphic> pdgraphic = content; SaveObjectGraphic(pContent, pdgraphic, matpdf, pageRect); } } } }