Ejemplo n.º 1
0
void CLocalSearch::SendHits(const CList< T* >& oFiles)
{
	CPacket* pPacket = NULL;
	CSchemaMap pSchemas;

	BYTE nHits = 0;
	for ( POSITION pos = oFiles.GetHeadPosition(); pos; )
	{
		if ( ! pPacket )
			pPacket = CreatePacket();

		AddHit( pPacket, pSchemas, oFiles.GetNext( pos ), nHits ++ );

		bool bSend = false;
		switch ( m_nProtocol )
		{
		case PROTOCOL_G1:
		case PROTOCOL_G2:
			bSend = nHits >= Settings.Gnutella.HitsPerPacket ||
				pPacket->m_nLength >= MAX_QUERY_PACKET_SIZE;
			break;
		case PROTOCOL_DC:
			// One hit per packet in DC++ protocol
			bSend = true;
			break;
		default:
			ASSERT( FALSE );
		}

		// Send full packet
		if ( bSend )
		{
			WriteTrailer( pPacket, pSchemas, nHits );
			DispatchPacket( pPacket );
			pPacket = NULL;
			nHits = 0;
		}
	}

	if ( nHits )
	{
		WriteTrailer( pPacket, pSchemas, nHits );
		DispatchPacket( pPacket );
		pPacket = NULL;
	}

	ASSERT( pPacket == NULL );
	ASSERT( pSchemas.IsEmpty() );
}
Ejemplo n.º 2
0
int CLocalSearch::ExecuteSharedFiles(int nMaximum)
{
	CQuickLock oLock( Library.m_pSection );
	CPtrList* pFiles = Library.Search( m_pSearch, nMaximum );
	if ( pFiles == NULL ) return 0;

	int nHits = pFiles->GetCount();

	while ( pFiles->GetCount() )
	{
		int nInThisPacket = min( pFiles->GetCount(), (int)Settings.Gnutella.HitsPerPacket );

		CreatePacket( nInThisPacket );

        int nHitB = 0;
		for ( int nHitA = 0 ; nHitA < nInThisPacket ; nHitA++ )
		{
			CLibraryFile* pFile = (CLibraryFile*)pFiles->RemoveHead();
			if ( AddHit( pFile, nHitB ) ) nHitB ++;
		}

		WriteTrailer();
		if ( nHitB > 0 ) DispatchPacket(); else DestroyPacket();
	}

	delete pFiles;

	return nHits;
}
Ejemplo n.º 3
0
/* This function handles writing out EPS files.  It is written to be
* as "PostScript friendly as possible", i.e. it:
*   1) Uses a fairly full set of DSC comments
*   2) Uses its own dictionary instead of assuming there is room in
*      the current one
*   3) If colorimage is not supported on the PostScript interpreter
*      and an RGB image was selected the image will be rendered as grayscale
*      instead using the NTSC conversion.
*/
BMMRES
	BitmapIO_EPS::Save(const TCHAR *name, Bitmap *bitmap) 
{
	int xOffset = 0;     // Offset for the lower left corner
	int yOffset = 0;     // of the image */
	int status;

	if (! bitmap) 
		return (ProcessImageIOError(&bi,BMMRES_INTERNALERROR));

	/* Compute the position on the page to output the image */
	Position (bitmap, &xOffset, &yOffset);

	// for a360 support - allows binary diff syncing
	MaxSDK::Util::Path storageNamePath(name);
	storageNamePath.SaveBaseFile();

	if ((mOutStream = _tfopen(name, _T("wb"))) == NULL)
		return (ProcessImageIOError(&bi));

	/* If a preview is desired then write the TIFF section */
	if (userSettings.preview)
	{
		status = WritePreview (userSettings.colorType, 
			userSettings.orientation,
			userSettings.xResolution,
			userSettings.yResolution,
			bitmap);
		if (status != BMMRES_SUCCESS)
		{
			fclose (mOutStream);
			return status;
		}
	}

	/* First the PostScript header */
	status = WriteHeader (bitmap, xOffset, yOffset);
	if (status != BMMRES_SUCCESS)
	{
		fclose (mOutStream);
		return status;
	}

	/* Now the image data itself */
	status = WriteImagePosition (bitmap, xOffset, yOffset);
	if (status != BMMRES_SUCCESS)
	{
		fclose (mOutStream);
		return status;
	}
	if (userSettings.binary && userSettings.colorType == RGBIMAGE)
		status = WriteBinaryRGBImage (bitmap);
	else if (userSettings.binary && userSettings.colorType == GRAYIMAGE)
		status = WriteBinaryGrayImage (bitmap);
	else if (userSettings.colorType == RGBIMAGE)
		status = WriteAsciiRGBImage (bitmap);
	else 
		status = WriteAsciiGrayImage (bitmap);
	if (status != BMMRES_SUCCESS)
	{
		fclose (mOutStream);
		return status;
	}

	/* Now the trailer */
	status = WriteTrailer ();

	/* If a preview was requested we need to now figure out the length of the
	* PostScript portion and write it to the header
	*/
	if (userSettings.preview)
		status = WritePSLength (userSettings.colorType, map);

	fclose (mOutStream);

	return (status);
}
Ejemplo n.º 4
0
PictSelection::PictSelection (istream& from, State* state) : (nil) {
    ReadPictGS(from, state);
    ReadChildren(from, state);
    valid = from.good();
}

// ReadChildren loops determining which kind of Selection follows and
// creating it until it reads "end" which means all of the children
// have been created.

void PictSelection::ReadChildren (istream& from, State* state) {
    while (from.good()) {
	Skip(from);
	Selection* child = nil;
	from >> buf;
	if (strcmp(buf, "BSpl") == 0) {
	    child = new BSplineSelection(from, state);
	} else if (strcmp(buf, "Circ") == 0) {
	    child = new	CircleSelection(from, state);
	} else if (strcmp(buf, "CBSpl") == 0) {
	    child = new	ClosedBSplineSelection(from, state);
	} else if (strcmp(buf, "Elli") == 0) {
	    child = new	EllipseSelection(from, state);
	} else if (strcmp(buf, "Line") == 0) {
	    child = new	LineSelection(from, state);
	} else if (strcmp(buf, "MLine") == 0) {
	    child = new	MultiLineSelection(from, state);
	} else if (strcmp(buf, "Pict") == 0) {
	    child = new	PictSelection(from, state);
	} else if (strcmp(buf, "Poly") == 0) {
	    child = new	PolygonSelection(from, state);
	} else if (strcmp(buf, "Rect") == 0) {
	    child = new	RectSelection(from, state);
	} else if (strcmp(buf, "Text") == 0) {
	    child = new	TextSelection(from, state);
	} else if (strcmp(buf, "eop") == 0) {
	    break;
	} else {
	    fprintf(stderr, "unknown Selection %s, skipping\n", buf);
	    continue;
	}
	if (from.good()) {
	    Append(child);
	} else {
	    delete child;
	}
    }
}

// WritePicture writes the picture's data and Postscript code to print
// it wrapped in Postscript comments that minimally conform to version
// 1.0 of Adobe Systems's structuring conventions for Postscript.  The
// picture must remove itself from its parent if it has a parent to
// prevent the parent's transformation from affecting the picture's
// calculation of its bounding box.

void PictSelection::WritePicture (ostream& to, boolean verbose) {
    Picture* parent = (Picture*) Parent();
    if (parent != nil) {
	parent->SetCurrent(this);
	parent->Remove(this);
    }

    ScaleToPostscriptCoords();
    if (verbose) {
	WriteComments(to);
	WritePrologue(to);
	WriteVersion(to);
	WriteGridSpacing(to);
	WriteDrawing(to);
	WriteTrailer(to);
    } else {
	WriteVersion(to);
	WriteGridSpacing(to);
	WriteDrawing(to);
    }
    ScaleToScreenCoords();

    if (parent != nil) {
	parent->InsertBeforeCur(this);
    }
}
Ejemplo n.º 5
0
HPDF_STATUS
HPDF_Xref_WriteToStream  (HPDF_Xref    xref,
                          HPDF_Stream  stream,
                          HPDF_Encrypt e)
{
    HPDF_STATUS ret;
    HPDF_UINT i;
    char buf[HPDF_SHORT_BUF_SIZ];
    char* pbuf;
    char* eptr = buf + HPDF_SHORT_BUF_SIZ - 1;
    HPDF_UINT str_idx;
    HPDF_Xref tmp_xref = xref;

    /* write each objects of xref to the specified stream */

    HPDF_PTRACE((" HPDF_Xref_WriteToStream\n"));

    while (tmp_xref) {
        if (tmp_xref->start_offset == 0)
            str_idx = 1;
        else
            str_idx = 0;

        for (i = str_idx; i < tmp_xref->entries->count; i++) {
            HPDF_XrefEntry  entry =
                        (HPDF_XrefEntry)HPDF_List_ItemAt (tmp_xref->entries, i);
            HPDF_UINT obj_id = tmp_xref->start_offset + i;
            HPDF_UINT16 gen_no = entry->gen_no;

            entry->byte_offset = stream->size;

            pbuf = buf;
            pbuf = HPDF_IToA (pbuf, obj_id, eptr);
            *pbuf++ = ' ';
            pbuf = HPDF_IToA (pbuf, gen_no, eptr);
            HPDF_StrCpy(pbuf, " obj\012", eptr);

            if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK)
               return ret;

            if (e)
                HPDF_Encrypt_InitKey (e, obj_id, gen_no);

            if ((ret = HPDF_Obj_WriteValue (entry->obj, stream, e)) != HPDF_OK)
                return ret;

            if ((ret = HPDF_Stream_WriteStr (stream, "\012endobj\012"))
                    != HPDF_OK)
                return ret;
       }

       tmp_xref = tmp_xref->prev;
    }

    /* start to write cross-reference table */

    tmp_xref = xref;

    while (tmp_xref) {
        tmp_xref->addr = stream->size;

        pbuf = buf;
        pbuf = (char *)HPDF_StrCpy (pbuf, "xref\012", eptr);
        pbuf = HPDF_IToA (pbuf, tmp_xref->start_offset, eptr);
        *pbuf++ = ' ';
        pbuf = HPDF_IToA (pbuf, tmp_xref->entries->count, eptr);
        HPDF_StrCpy (pbuf, "\012", eptr);
        ret = HPDF_Stream_WriteStr (stream, buf);
        if (ret != HPDF_OK)
            return ret;

        for (i = 0; i < tmp_xref->entries->count; i++) {
            HPDF_XrefEntry entry = HPDF_Xref_GetEntry(tmp_xref, i);

            pbuf = buf;
            pbuf = HPDF_IToA2 (pbuf, entry->byte_offset, HPDF_BYTE_OFFSET_LEN +
                    1);
            *pbuf++ = ' ';
            pbuf = HPDF_IToA2 (pbuf, entry->gen_no, HPDF_GEN_NO_LEN + 1);
            *pbuf++ = ' ';
            *pbuf++ = entry->entry_typ;
            HPDF_StrCpy (pbuf, "\015\012", eptr);
            ret = HPDF_Stream_WriteStr (stream, buf);
            if (ret != HPDF_OK)
                return ret;
        }

        tmp_xref = tmp_xref->prev;
    }

    /* write trailer dictionary */
    ret = WriteTrailer (xref, stream);

    return ret;
}