Beispiel #1
0
void Font::loadCommonBlock(std::istream &ss, unsigned int blockSize, int version)
{
	CommonBlock block;

	ReadRaw(ss, block.lineHeight);
	ReadRaw(ss, block.base);
	ReadRaw(ss, block.scaleW);
	ReadRaw(ss, block.scaleH);
	ReadRaw(ss, block.pages);
	ReadRaw(ss, block.flags);

	if (version == 1 || version == 3) // encoded was added in version 2 and removed in version 3 (lol?)
		block.flags &= kBlockPacked;
	else if (version == 2)
		block.flags &= kBlockPacked | kBlockEncoded;

	if (version == 3)
	{
		ReadRaw(ss, block.alphaChnl);
		ReadRaw(ss, block.redChnl);
		ReadRaw(ss, block.greenChnl);
		ReadRaw(ss, block.blueChnl);
	}

	mLineHeight = static_cast<float>(block.lineHeight);
	mBase = static_cast<float>(block.base);
}
Beispiel #2
0
void Font::loadFromFile(const char *fname)
{
	std::ifstream ss(fname, std::ios::in | std::ios::binary);

	std::string dir(fname);
	size_t pos = dir.find_last_of("/\\");
	if (pos != std::string::npos)
		dir = dir.substr(0, pos + 1);
	else
		dir = "";

	// check for a valid header
	char magic[3];
	ReadRaw(ss, magic);
	if (memcmp(magic, "BMF", sizeof(magic)) != 0)
		throw std::runtime_error("Invalid font file (no magic code)");

	unsigned char version;
	ReadRaw(ss, version);
	if (version > 3)
		throw std::runtime_error("Cannot load font file (unsupported file version)");

	while (ss.good())
	{
		unsigned char blockType;
		ReadRaw(ss, blockType);
		if (! ss.good()) break;

		unsigned int blockSize;
		ReadRaw(ss, blockSize);
		if (! ss.good())
			throw std::runtime_error("Cannot load font file (file is truncated; ends after a block type tag)");

		// before version 3, the blockSize included the size field itself
		if (version < 3)
			blockSize -= 4;

		switch (blockType)
		{
		case kBlockTypeInfo:
			loadInfoBlock(ss, blockSize, version);
			break;
		case kBlockTypeCommon:
			loadCommonBlock(ss, blockSize, version);
			break;
		case kBlockTypePages:
			loadPagesBlock(ss, blockSize, version, dir);
			break;
		case kBlockTypeChars:
			loadCharsBlock(ss, blockSize, version);
			break;
		case kBlockTypeKerning:
			loadKerningBlock(ss, blockSize, version);
			break;
		default:
			throw std::runtime_error("Cannot load font file (file contains a block of unknown type)");
			break;
		}
	}
}
Beispiel #3
0
//Checks the given sensor values and returns and array of bools.
bool Sensor::GetReading() {
	ReadRaw();
	UpdateRange();
	Normalise();
	toTileColour();
	return tileWhite;
}
Beispiel #4
0
void Font::loadPagesBlock(std::istream &ss, unsigned int blockSize, int version, const std::string &baseDir)
{
	// load the texture for the first page
	// FIXME: support multiple page fonts??

	PagesBlock block;

	unsigned int fnameLength = blockSize - sizeof(block);
	std::string fname;
	fname.reserve(fnameLength);

	unsigned int pos = 0;
	while (ss.good() && (pos < blockSize))
	{
		char c;
		ReadRaw(ss, c);
		pos += 1;
		if (c == 0)
			break;
		else
			fname += c;
	}

	if (pos != blockSize)
		throw std::runtime_error("Cannot load font file (pages block is truncated or has an incorrect blockSize)");

	mTexture->loadFromFile((baseDir + fname).c_str(), false, Texture::FormatAlpha);
}
// Tests a PTY subprocess with no protocol.
TEST_F(ShellServiceTest, PtyNoProtocolSubprocess) {
    // [ -t 0 ] checks if stdin is connected to a terminal.
    ASSERT_NO_FATAL_FAILURE(StartTestSubprocess(
                                "echo foo; echo bar >&2; [ -t 0 ]; echo $?",
                                SubprocessType::kPty, SubprocessProtocol::kNone));

    // [ -t 0 ] == 0 means we have a terminal (PTY).
    ExpectLinesEqual(ReadRaw(subprocess_fd_), {"foo", "bar", "0"});
}
Beispiel #6
0
/**
 *   Read the current temperature in degrees F.
 *
 *   @return temperature in units of 0.1 degrees F
 */
int32_t LM92::ReadTempF()
{
    int32_t value;

    if ((value = ReadRaw()) == -999)
        return -999;
    
    // Convert from raw units to degrees F.  
    // See the LM72_92.xls Spreadsheet in the .../unit_test directory for additional information.
    return ((9 * value) / 64) + 320;
}
Beispiel #7
0
/**
 *   Read the current temperature in degrees F.
 *
 *   @return temperature in units of 0.1 degrees F
 */
int32_t LM92::ReadTempC()
{
    int32_t value;

    if ((value = ReadRaw()) == -999)
        return -999;
    
    // Convert from degC to degF.
    // See the LM72_92.xls Spreadsheet in the .../unit_test directory for additional information.    
    return ((5 * value) / 64);
}
unsigned char * VFSHandle_ZIP::Read(unsigned int &length)
{
	LocalFileHeader *lfh = m_lfh[m_fileid];

	m_stream.clear();
	m_stream.seekg(lfh->file_data_offset,std::ios::beg);

	unsigned char *buffer = NULL;

	if(lfh->compression_method == NO_COMPRESSION){
		//	Files are just stored
		buffer = ReadRaw(m_length);

	}else if(lfh->compression_method == DEFLATE_COMPRESSION){
		//	Files are deflated

		//	Read compressed data from the disk
		unsigned char *src = ReadRaw(lfh->comp_size);

		//	Allocate a buffer for the decompressed data
		buffer = new unsigned char[length];

		//	setup the z_stream structure
		memset(&m_zipstream,0,sizeof(z_stream));

		m_zipstream.avail_in	= lfh->comp_size;
		m_zipstream.next_in		=	src; 

		m_zipstream.avail_out	= m_length;
		m_zipstream.next_out	=	buffer;

		inflateInit2(&m_zipstream,-15);
		inflate(&m_zipstream,Z_FINISH);
		inflateEnd(&m_zipstream);

		delete[] src;
	}

	return buffer;
}
Beispiel #9
0
void Font::loadKerningBlock(std::istream &ss, unsigned int blockSize, int version)
{
	KerningPairsBlock::KerningPair info;

	unsigned int pos = 0;
	while (ss.good() && (pos < blockSize))
	{
		if (version < 3)
		{
			unsigned short ids;
			ReadRaw(ss, ids);
			info.first = ids;
			ReadRaw(ss, ids);
			info.second = ids;
		}
		else
		{
			ReadRaw(ss, info.first);
			ReadRaw(ss, info.second);
		}
		
		ReadRaw(ss, info.amount);

		if (version < 3)
			pos += 6;
		else
			pos += 10;

		if (info.first >= 256 || info.second >= 256)
			continue;

		mKerningPairs.insert(std::make_pair(
			CharPair(static_cast<char>(info.first), static_cast<char>(info.second)),
			static_cast<float>(info.amount)
		));
	}

	if (pos != blockSize)
		throw std::runtime_error("Cannot load font file (kerning block is truncated or has an incorrect blockSize)");
}
Beispiel #10
0
size_t wxBZipInputStream::OnSysRead(void* buffer, size_t bufsize)
{
    bz_stream* hZip = (bz_stream*)m_hZip;

	hZip->next_out = (char*)buffer;
	hZip->avail_out = bufsize;

	while (hZip->avail_out != 0)
	{
		if (m_nBufferPos == 0 || m_nBufferPos == WXBZBS)
		{
			ReadRaw(m_pBuffer, WXBZBS);
			
            m_nBufferPos = 0;
			hZip->next_in = m_pBuffer;
			hZip->avail_in = WXBZBS;

            if (m_parent_i_stream->LastRead() != WXBZBS)
			{
                // Full amount not read, so do a last
                // minute tidy up and decompress what is left
				hZip->avail_in = m_parent_i_stream->LastRead();

				int nRet = BZ2_bzDecompress(hZip);

				if (nRet == BZ_OK || nRet == BZ_STREAM_END)
					return bufsize - hZip->avail_out;
				else
					return 0;
			}
		}

        // Buffer full, decompress some bytes
        hZip->next_in = &m_pBuffer[m_nBufferPos];
		hZip->avail_in = WXBZBS - m_nBufferPos;

		int nRet = BZ2_bzDecompress(hZip);

		if (nRet == BZ_OK)	
		{
			m_nBufferPos = WXBZBS - hZip->avail_in;
		}
		else if(nRet == BZ_STREAM_END)
			return bufsize - hZip->avail_out;
		else
			return 0;	
	}
 
	return bufsize - hZip->avail_out;	
}
Beispiel #11
0
RoOptionalUInt32 RoCli::ReadInteger(std::string message, bool isPassword, optional<RoButtonSoundPtr> buttonSound)
{
    RoOptionalUtf8 rawInput = ReadRaw(message, isPassword, INTEGER_CHARS, buttonSound);
    if (rawInput.is_initialized())
    {
        char* endChar;
        const std::string inputString = rawInput->asUTF8();
        uint32 result = strtol(&inputString[0], &endChar, 0);
        if (*endChar == 0)
        {
            return RoOptionalUInt32{ result };
        }
    }
    return RoOptionalUInt32{};
}
Beispiel #12
0
size_t wxBZipInputStream::OnSysRead(void* buffer, size_t bufsize)
{
	wxInt32 nRead = 0;

	((bz_stream*&)hZip)->next_out = &(((char*&)buffer)[nRead]);
	((bz_stream*&)hZip)->avail_out = bufsize - nRead;

	while (((bz_stream*&)hZip)->avail_out != 0)
	{
		//wxMessageBox(wxString::Format("%i %i", nRead, ((bz_stream*&)hZip)->avail_out));

		if (nBufferPos == 0 || nBufferPos == WXBZBS)
		{
			ReadRaw(pBuffer, WXBZBS);
			nBufferPos = 0;
			((bz_stream*&)hZip)->next_in = &pBuffer[nBufferPos];
			((bz_stream*&)hZip)->avail_in = WXBZBS - nBufferPos;
			if (m_parent_i_stream->LastRead() != WXBZBS)
			{
				((bz_stream*&)hZip)->avail_in = m_parent_i_stream->LastRead();

				int nRet = BZ2_bzDecompress((bz_stream*&)hZip);

				if (nRet == BZ_OK || nRet == BZ_STREAM_END)
					return bufsize - ((bz_stream*&)hZip)->avail_out;
				else
					return 0;
			}
		}
		((bz_stream*&)hZip)->next_in = &pBuffer[nBufferPos];
		((bz_stream*&)hZip)->avail_in = WXBZBS - nBufferPos;

		int nRet = BZ2_bzDecompress((bz_stream*&)hZip);

		if (nRet == BZ_OK)	
		{
			nBufferPos += -(nRead - (
			nRead += (WXBZBS - nBufferPos - ((bz_stream*&)hZip)->avail_in)
			));
		}
		else if(nRet == BZ_STREAM_END)
			return bufsize - ((bz_stream*&)hZip)->avail_out;
		else
			return 0;	
	}
 
	return bufsize - ((bz_stream*&)hZip)->avail_out;	
}
Beispiel #13
0
RoOptionalUtf8 RoCli::ReadString(std::string message, bool isPassword, optional<RoButtonSoundPtr> buttonSound)
{
    return ReadRaw(message, isPassword, TEXT_SPECIAL_CHARS, buttonSound);
}
Beispiel #14
0
int CMFTRecord::ExtractData(NTFS_ATTRIBUTE ntfsAttr, BYTE *&puchData, DWORD &dwDataLen) {
    DWORD dwCurPos = m_dwCurPos;

    if (!ntfsAttr.uchNonResFlag) {// residence attribute, this always resides in the MFT table itself

        puchData = new BYTE[ntfsAttr.Attr.Resident.dwLength];
        dwDataLen = ntfsAttr.Attr.Resident.dwLength;

        memcpy(puchData, &m_pMFTRecord[dwCurPos + ntfsAttr.Attr.Resident.wAttrOffset], dwDataLen);
    } else {// non-residence attribute, this resides in the other part of the physical drive

        if (!ntfsAttr.Attr.NonResident.n64AllocSize) // i don't know Y, but fails when its zero
            ntfsAttr.Attr.NonResident.n64AllocSize = (ntfsAttr.Attr.NonResident.n64EndVCN - ntfsAttr.Attr.NonResident.n64StartVCN) + 1;

        // ATTR_STANDARD size may not be correct
        dwDataLen = ntfsAttr.Attr.NonResident.n64RealSize;

        // allocate for reading data
        puchData = new BYTE[ntfsAttr.Attr.NonResident.n64AllocSize];

        BYTE chLenOffSz; // length & offset sizes
        BYTE chLenSz; // length size
        BYTE chOffsetSz; // offset size
        LONGLONG n64Len, n64Offset; // the actual lenght & offset
        LONGLONG n64LCN = 0; // the pointer pointing the actual data on a physical disk
        BYTE *pTmpBuff = puchData;
        int nRet;

        dwCurPos += ntfsAttr.Attr.NonResident.wDatarunOffset;
        ;

        for (;;) {
            ///// read the length of LCN/VCN and length ///////////////////////
            chLenOffSz = 0;

            memcpy(&chLenOffSz, &m_pMFTRecord[dwCurPos], sizeof (BYTE));

            dwCurPos += sizeof (BYTE);

            if (!chLenOffSz)
                break;

            chLenSz = chLenOffSz & 0x0F;
            chOffsetSz = (chLenOffSz & 0xF0) >> 4;

            ///// read the data length ////////////////////////////////////////

            n64Len = 0;

            memcpy(&n64Len, &m_pMFTRecord[dwCurPos], chLenSz);

            dwCurPos += chLenSz;

            ///// read the LCN/VCN offset //////////////////////////////////////

            n64Offset = 0;

            memcpy(&n64Offset, &m_pMFTRecord[dwCurPos], chOffsetSz);

            dwCurPos += chOffsetSz;

            ////// if the last bit of n64Offset is 1 then its -ve so u got to make it -ve /////
            if ((((char*) &n64Offset)[chOffsetSz - 1])&0x80)
                for (int i = sizeof (LONGLONG) - 1; i > (chOffsetSz - 1); i--)
                    ((char*) &n64Offset)[i] = 0xff;

            n64LCN += n64Offset;

            n64Len *= m_dwBytesPerCluster;
            ///// read the actual data /////////////////////////////////////////
            /// since the data is available out side the MFT table, physical drive should be accessed
            nRet = ReadRaw(n64LCN, pTmpBuff, (DWORD&) n64Len);
            if (nRet)
                return nRet;

            pTmpBuff += n64Len;
        }
    }
    return ERROR_SUCCESS;
}
Beispiel #15
0
void Font::loadCharsBlock(std::istream &ss, unsigned int blockSize, int version)
{
	CharsBlock::CharInfo c;

	vec2i texSize = mTexture->getSize();

	unsigned int pos = 0;
	while (ss.good() && (pos < blockSize))
	{
		if (version < 3)
		{
			unsigned short ids;
			ReadRaw(ss, ids);
			c.id = ids;
		}
		else
			ReadRaw(ss, c.id);
		ReadRaw(ss, c.x);
		ReadRaw(ss, c.y);
		ReadRaw(ss, c.width);
		ReadRaw(ss, c.height);
		ReadRaw(ss, c.xoffset);
		ReadRaw(ss, c.yoffset);
		ReadRaw(ss, c.xadvance);
		ReadRaw(ss, c.page);
		ReadRaw(ss, c.chnl);

		if (version < 3)
			pos += 18;
		else
			pos += 20;

		if (c.id >= 256)
			continue;

		CharInfo &info = mCharMetrics[c.id];

		info.draw = true;
		info.advance = static_cast<float>(c.xadvance + 1);
		info.posTopLeft = vec2f(
			static_cast<float>(c.xoffset),
			static_cast<float>(c.yoffset)
		);
		info.posBottomRight = vec2f(
			static_cast<float>(c.xoffset + c.width),
			static_cast<float>(c.yoffset + c.height)
		);
		info.texTopLeft = vec2f(
			static_cast<float>(c.x) / static_cast<float>(texSize.x),
			static_cast<float>(c.y) / static_cast<float>(texSize.y)
		);
		info.texBottomRight = vec2f(
			static_cast<float>(c.x + c.width ) / static_cast<float>(texSize.x),
			static_cast<float>(c.y + c.height) / static_cast<float>(texSize.y)
		);
	}

	if (pos != blockSize)
		throw std::runtime_error("Cannot load font file (chars block is truncated or has an incorrect blockSize)");

	// hard-code for space and tab
	mCharMetrics[' '].draw = false;
	mCharMetrics['\t'].draw = false;
	mCharMetrics['\t'].advance = 4.0f * mCharMetrics[' '].advance;
}
Beispiel #16
0
void Font::loadInfoBlock(std::istream &ss, unsigned int blockSize, int version)
{
	InfoBlock block;
	
	ReadRaw(ss, block.fontSize);
	ReadRaw(ss, block.flags);
	ReadRaw(ss, block.charSet);
	ReadRaw(ss, block.stretchH);
	ReadRaw(ss, block.aa);
	ReadRaw(ss, block.paddingUp);
	ReadRaw(ss, block.paddingRight);
	ReadRaw(ss, block.paddingDown);
	ReadRaw(ss, block.paddingLeft);
	ReadRaw(ss, block.spacingHoriz);
	ReadRaw(ss, block.spacingVert);
	if (version >= 2)
		ReadRaw(ss, block.outline);

	block.flags &= kFontBold | kFontItalic | kFontUnicode | kFontSmooth;

	// font face name
	unsigned char faceNameLength = blockSize - sizeof(block);
	mFaceName.clear();
	mFaceName.reserve(faceNameLength);

	unsigned int pos = sizeof(block) - 1;
	while (ss.good() && (pos < blockSize))
	{
		char c;
		ReadRaw(ss, c);
		if (c == 0)
			break;
		else
			mFaceName += c;
	}
}