FSDefineJPEGImage2& FSDefineJPEGImage2::operator= (const FSDefineJPEGImage2& rhs) { if (this != &rhs) { this->FSDefineObject::operator=(rhs); width = rhs.width; height = rhs.height; imageLength = rhs.imageLength; encodingLength = rhs.encodingLength; delete [] image; image = new byte[imageLength]; if (imageLength > 0 && image == 0) throw FSAllocationException("Cannot allocate memory for image."); memcpy(image, rhs.image, imageLength*sizeof(byte)); delete [] encodingTable; encodingTable = new byte[encodingLength]; if (encodingLength > 0 && encodingTable == 0) throw FSAllocationException("Cannot allocate memory for encoding table."); memcpy(encodingTable, rhs.encodingTable, encodingLength*sizeof(byte)); } return *this; }
FSJPEGEncodingTable& FSJPEGEncodingTable::operator= (const FSJPEGEncodingTable& rhs) { if (this != &rhs) { this->FSMovieObject::operator=(rhs); if (rhs.encodingTable != 0) { delete [] encodingTable; encodingTable = new byte[length]; if (length > 0 && encodingTable == 0) throw FSAllocationException("Could not allocate memory to copy a JPEG encoding table."); for (int i=0; i<rhs.length; i++) encodingTable[i] = rhs.encodingTable[i]; } else { encodingTable = 0; length = 2; } } return *this; }
const FSString& FSString::operator+=(const FSString& rhs) { if (this == &rhs) { FSString copy(rhs); return *this += copy; } int newLength = length() + rhs.length(); if (newLength >= bufferLength) { bufferLength = 2 * (newLength + 1); char* oldBuffer = buffer; buffer = new char[ bufferLength ]; if (bufferLength > 0 && buffer == 0) throw FSAllocationException("Cannot allocate memory to copy an FSString."); strcpy(buffer, oldBuffer ); delete [] oldBuffer; } strcpy(buffer+length(), rhs.buffer); strLength = newLength; return *this; }
FSDefineJPEGImage2::FSDefineJPEGImage2(const FSDefineJPEGImage2& rhs) : FSDefineObject(rhs), width(rhs.width), height(rhs.height) { image = new byte[rhs.imageLength]; imageLength = rhs.imageLength; if (imageLength > 0 && image == 0) throw FSAllocationException("Cannot allocate memory for image."); memcpy(image, rhs.image, imageLength*sizeof(byte)); encodingTable = new byte[rhs.encodingLength]; encodingLength = rhs.encodingLength; if (encodingLength > 0 && encodingTable == 0) throw FSAllocationException("Cannot allocate memory for encoding table."); memcpy(encodingTable, rhs.encodingTable, encodingLength*sizeof(byte)); }
FSString::FSString(const FSString& rhs) : FSValue(rhs), buffer(0), strLength(0), bufferLength(0) { strLength = rhs.length(); bufferLength = strLength + 1; buffer = new char[bufferLength]; if (bufferLength > 0 && buffer == 0) throw FSAllocationException("Cannot allocate memory to copy an FSString."); strcpy(buffer, rhs.buffer); }
FSUnknownAction::FSUnknownAction(const FSUnknownAction& rhs) : FSActionObject(rhs) , data(0) { if (rhs.data) { data = new byte[length]; if (length > 0 && data == 0) throw FSAllocationException("Cannot allocate memory to copy and FSUnknownAction."); memcpy(data, rhs.data, length*sizeof(byte)); } }
FSString::FSString(FSInputStream* aStream) : FSValue(FSValue::String), buffer(0), strLength(0), bufferLength(0) { strLength = 0; bufferLength = strLength + 1; buffer = new char[bufferLength]; if (bufferLength > 0 && buffer == 0) throw FSAllocationException("Cannot allocate memory to copy an FSString."); buffer[0] = '\0'; decodeFromStream(aStream); }
FSString::FSString(const char* aValue) : FSValue(FSValue::String), buffer(0), strLength(0), bufferLength(0) { if (aValue == 0) aValue = ""; strLength = (int)strlen(aValue); bufferLength = strLength + 1; buffer = new char[bufferLength]; if (bufferLength > 0 && buffer == 0) throw FSAllocationException("Cannot allocate memory to copy an FSString."); strcpy(buffer, aValue); }
FSUnknownAction& FSUnknownAction::operator= (const FSUnknownAction& rhs) { if (this != &rhs) { this->FSActionObject::operator=(rhs); data = new byte[length]; if (length > 0 && data == 0) throw FSAllocationException("Cannot allocate memory to copy and FSUnknownAction."); memcpy(data, rhs.data, length*sizeof(byte)); } return *this; }
FSDefineImage::FSDefineImage(const FSDefineImage& rhs) : FSDefineObject(rhs), width(rhs.width), height(rhs.height), pixelSize(rhs.pixelSize), tableSize(rhs.tableSize), imageLength(rhs.imageLength), image(0) { image = new byte[imageLength]; if (imageLength > 0 && image == 0) throw FSAllocationException("Cannot allocate memory for image."); memcpy(image, rhs.image, imageLength*sizeof(byte)); }
FSJPEGEncodingTable::FSJPEGEncodingTable(const FSJPEGEncodingTable& rhs) : FSMovieObject(rhs), encodingTable(0) { if (rhs.encodingTable != 0) { encodingTable = new byte[length]; if (length > 0 && encodingTable == 0) throw FSAllocationException("Could not allocate memory to copy a JPEG encoding table."); memcpy(encodingTable, rhs.encodingTable, length*sizeof(byte)); } else { encodingTable = 0; length = 2; } }
const FSString& FSString::operator= (const FSString& rhs) { if (this != &rhs) { this->FSValue::operator=(rhs); if (bufferLength < rhs.length() + 1) { delete [] buffer; bufferLength = rhs.length() + 1; buffer = new char[bufferLength]; if (bufferLength > 0 && buffer == 0) throw FSAllocationException("Cannot allocate memory to copy an FSString."); } strLength = rhs.length(); strcpy(buffer, rhs.buffer); } return *this; }
FSDefineImage& FSDefineImage::operator= (const FSDefineImage& rhs) { if (this != &rhs) { this->FSDefineObject::operator=(rhs); width = rhs.width; height = rhs.height; pixelSize = rhs.pixelSize; tableSize = rhs.tableSize; imageLength = rhs.imageLength; delete [] image; image = new byte[imageLength]; if (imageLength > 0 && image == 0) throw FSAllocationException("Cannot allocate memory for image."); memcpy(image, rhs.image, imageLength*sizeof(byte)); } return *this; }
void FSPush::decodeFromStream(FSInputStream* aStream) { int valuesLength = 0; #ifdef _DEBUG aStream->startDecoding(className()); #endif FSActionObject::decodeFromStream(aStream); valuesLength = getLength(); #ifdef _DEBUG aStream->startDecoding("array"); #endif while (valuesLength > 0) { FSValue* currentValue; int valueType = aStream->scan(FSStream::UnsignedWord, 8); aStream->setCursor(aStream->getCursor()-8); switch (valueType) { case 0: currentValue = new FSString(aStream); break; case 1: // Pre version 5 property currentValue = new FSInteger(aStream); break; case 2: currentValue = new FSNull(aStream); break; case 3: currentValue = new FSVoid(aStream); break; case 4: currentValue = new FSRegisterIndex(aStream); break; case 5: currentValue = new FSBoolean(aStream); break; case 6: currentValue = new FSDouble(aStream); break; case 7: currentValue = new FSInteger(aStream); break; case 8: case 9: currentValue = new FSTableIndex(aStream); break; } if (currentValue == 0) throw FSAllocationException("Cannot allocate new data type for FSPush object."); switch (valueType) { case 0: valuesLength -= currentValue->length()+2; break; case 1: valuesLength -= 5; break; case 2: valuesLength -= 1; break; case 3: valuesLength -= 1; break; case 4: valuesLength -= 2; break; case 5: valuesLength -= 2; break; case 6: valuesLength -= 9; break; case 7: valuesLength -= 5; break; case 8: valuesLength -= 2; break; case 9: valuesLength -= 3; break; } values.push_back(currentValue); } #ifdef _DEBUG aStream->endDecoding("array"); aStream->endDecoding(className()); #endif }
void FSDefineFont2::decodeFromStream(FSInputStream* aStream) { bool containsWideOffsets = false; bool containsWideCodes = false; bool containsLayout = false; int glyphCount = 0; int kerningCount = 0; int nameLength = 0; int codeOffset = 0; aStream->startDecoding(className()); FSDefineObject::decodeFromStream(aStream); containsLayout = aStream->read(FSStream::UnsignedBit, 1) != 0 ? true : false; int format = aStream->read(FSStream::UnsignedBit, 3); if (format == 1) encoding = FSText::ANSI; else if (format == 2) small = true; else if (format == 4) encoding = FSText::SJIS; containsWideOffsets = aStream->read(FSStream::UnsignedBit, 1) != 0 ? true : false; containsWideCodes = aStream->read(FSStream::UnsignedBit, 1) != 0 ? true : false; aStream->setContext(FSStream::WideCodes, containsWideCodes); italic = aStream->read(FSStream::UnsignedBit, 1) != 0 ? true : false; bold = aStream->read(FSStream::UnsignedBit, 1) != 0 ? true : false; language = aStream->read(FSStream::UnsignedBit, 8); nameLength = aStream->read(FSStream::UnsignedWord, 8); char* dst = new char[nameLength+1]; char* src = (char*)aStream->read(nameLength); if (dst == 0) throw FSAllocationException("Cannot allocate memory for font name."); strncpy(dst, src, nameLength); dst[nameLength] = '\0'; name = dst; delete [] src; delete [] dst; glyphCount = aStream->read(FSStream::UnsignedWord, 16); #ifdef _DEBUG aStream->startDecoding("array"); #endif for (int i=0; i<glyphCount; i++) aStream->read(FSStream::UnsignedWord, (containsWideOffsets) ? 32 : 16); #ifdef _DEBUG aStream->endDecoding("array"); #endif codeOffset = aStream->read(FSStream::UnsignedWord, (containsWideOffsets) ? 32 : 16); #ifdef _DEBUG aStream->startDecoding("array"); #endif for (int i=0; i<glyphCount; i++) shapes.push_back(FSShape(aStream)); #ifdef _DEBUG aStream->endDecoding("array"); aStream->startDecoding("array"); #endif for (int i=0; i<glyphCount; i++) codes.push_back(aStream->read(FSStream::UnsignedWord, (containsWideCodes) ? 16 : 8)); #ifdef _DEBUG aStream->endDecoding("array"); #endif if (containsLayout) { ascent = aStream->read(FSStream::SignedWord, 16); descent = aStream->read(FSStream::SignedWord, 16); leading = aStream->read(FSStream::SignedWord, 16); #ifdef _DEBUG aStream->startDecoding("array"); #endif for (int i=0; i<glyphCount; i++) advances.push_back(aStream->read(FSStream::SignedWord, 16)); #ifdef _DEBUG aStream->endDecoding("array"); aStream->startDecoding("array"); #endif for (int i=0; i<glyphCount; i++) bounds.push_back(FSBounds(aStream)); #ifdef _DEBUG aStream->endDecoding("array"); #endif kerningCount = aStream->read(FSStream::UnsignedWord, 16); #ifdef _DEBUG aStream->startDecoding("array"); #endif for (int i=0; i<kerningCount; i++) kernings.push_back(FSKerning(aStream)); #ifdef _DEBUG aStream->endDecoding("array"); #endif } aStream->setContext(FSStream::WideCodes, 0); aStream->endDecoding(className()); }