JSON::JSONArray JSON::fromPoint(const Point& point)
{
    JSONArray array;

    array.push_back(fromNumber(point.x()));
    array.push_back(fromNumber(point.y()));

    return array;
}
예제 #2
0
Component
Component::fromSequenceNumber(uint64_t seqNo)
{
  return g_conventionEncoding == Convention::MARKER ?
         fromNumberWithMarker(SEQUENCE_NUMBER_MARKER, seqNo) :
         fromNumber(seqNo, tlv::SequenceNumNameComponent);
}
예제 #3
0
Component
Component::fromByteOffset(uint64_t offset)
{
  return g_conventionEncoding == Convention::MARKER ?
         fromNumberWithMarker(SEGMENT_OFFSET_MARKER, offset) :
         fromNumber(offset, tlv::ByteOffsetNameComponent);
}
예제 #4
0
Component
Component::fromSegment(uint64_t segmentNo)
{
  return g_conventionEncoding == Convention::MARKER ?
         fromNumberWithMarker(SEGMENT_MARKER, segmentNo) :
         fromNumber(segmentNo, tlv::SegmentNameComponent);
}
예제 #5
0
Component
Component::fromVersion(uint64_t version)
{
  return g_conventionEncoding == Convention::MARKER ?
         fromNumberWithMarker(VERSION_MARKER, version) :
         fromNumber(version, tlv::VersionNameComponent);
}
예제 #6
0
Component
Component::fromTimestamp(const time::system_clock::TimePoint& timePoint)
{
  uint64_t value = time::duration_cast<time::microseconds>(timePoint - time::getUnixEpoch()).count();
  return g_conventionEncoding == Convention::MARKER ?
         fromNumberWithMarker(TIMESTAMP_MARKER, value) :
         fromNumber(value, tlv::TimestampNameComponent);
}
bool PluckerBookReader::readDocument() {
	myStream = ZLFile(myFilePath).inputStream();
	if (myStream.isNull() || !myStream->open()) {
		return false;
	}

	PdbHeader header;
	if (!header.read(myStream)) {
		myStream->close();
		return false;
	}

	setMainTextModel();
	myFont = FT_REGULAR;

	for (std::vector<unsigned long>::const_iterator it = header.Offsets.begin(); it != header.Offsets.end(); ++it) {
		size_t currentOffset = myStream->offset();
		if (currentOffset > *it) {
			break;
		}
		myStream->seek(*it - currentOffset, false);
		if (myStream->offset() != *it) {
			break;
		}
		size_t recordSize = ((it != header.Offsets.end() - 1) ? *(it + 1) : myStream->sizeOfOpened()) - *it;
		readRecord(recordSize);
	}
	myStream->close();

	for (std::set<std::pair<int,int> >::const_iterator it = myReferencedParagraphs.begin(); it != myReferencedParagraphs.end(); ++it) {
		std::map<int,std::vector<int> >::const_iterator jt = myParagraphMap.find(it->first);
		if (jt != myParagraphMap.end()) {
			for (unsigned int k = it->second; k < jt->second.size(); ++k) {
				if (jt->second[k] != -1) {
					addHyperlinkLabel(fromNumber(it->first) + '#' + fromNumber(it->second), jt->second[k]);
					break;
				}
			}
		}
	}
	myReferencedParagraphs.clear();
	myParagraphMap.clear();
	return true;
}
/**
 * Gets current date time.
 *
 * Example: 20070323112132
 * 2007-03-23 11:21:32 (YYYY-MM-DD HH:MM:SS)
 */
std::string getCurrentDateTime() {
	std::time_t currentTime = time(NULL);
	struct std::tm * timeInfo = std::localtime(&currentTime);

	std::string month = fromNumber(timeInfo->tm_mon + 1);
	std::string day = fromNumber(timeInfo->tm_mday);
	std::string year = fromNumber(timeInfo->tm_year + 1900);

	std::string hour = fromNumber(timeInfo->tm_hour);
	std::string minute = fromNumber(timeInfo->tm_min);
	std::string second = fromNumber(timeInfo->tm_sec);

	if (month.size() == 1) {
		month = "0" + month;
	}

	if (day.size() == 1) {
		day = "0" + day;
	}

	if (hour.size() == 1) {
		hour = "0" + hour;
	}

	if (minute.size() == 1) {
		minute = "0" + minute;
	}

	if (second.size() == 1) {
		second = "0" + second;
	}

	return year + month + day + hour + minute + second;
}
void PluckerBookReader::readRecord(size_t recordSize) {
	unsigned short uid;
	PdbUtil::readUnsignedShort(*myStream, uid);
	if (uid == 1) {
		PdbUtil::readUnsignedShort(*myStream, myCompressionVersion);
	} else {
		unsigned short paragraphs;
		PdbUtil::readUnsignedShort(*myStream, paragraphs);

		unsigned short size;
		PdbUtil::readUnsignedShort(*myStream, size);

		unsigned char type;
		myStream->read((char*)&type, 1);

		unsigned char flags;
		myStream->read((char*)&flags, 1);

		switch (type) {
			case 0: // text (TODO: found sample file and test this code)
			case 1: // compressed text
			{
				std::vector<int> pars;
				for (int i = 0; i < paragraphs; ++i) {
					unsigned short pSize;
					PdbUtil::readUnsignedShort(*myStream, pSize);
					pars.push_back(pSize);
					myStream->seek(2, false);
				}

				bool doProcess = false;
				if (type == 0) {
					doProcess = myStream->read(myCharBuffer, size) == size;
				} else if (myCompressionVersion == 1) {
					doProcess =
						DocDecompressor().decompress(*myStream, myCharBuffer, recordSize - 8 - 4 * paragraphs, size) == size;
				} else if (myCompressionVersion == 2) {
					myStream->seek(2, false);
					doProcess =
						ZLZDecompressor(recordSize - 10 - 4 * paragraphs).
							decompress(*myStream, myCharBuffer, size) == size;
				}
				if (doProcess) {
					addHyperlinkLabel(fromNumber(uid));
					myParagraphVector = &myParagraphMap[uid];
					processTextRecord(size, pars);
					if ((flags & 0x1) == 0) {
						insertEndOfTextParagraph();
					}
				}
				break;
			}
			case 2: // image
			case 3: // compressed image
			{
				static const std::string mime = "image/palm";
				ZLImage *image = 0;
				if (type == 2) {
					image = new ZLFileImage(mime, myFilePath, myStream->offset(), recordSize - 8);
				} else if (myCompressionVersion == 1) {
					image = new DocCompressedFileImage(mime, myFilePath, myStream->offset(), recordSize - 8);
				} else if (myCompressionVersion == 2) {
					image = new ZCompressedFileImage(mime, myFilePath, myStream->offset() + 2, recordSize - 10);
				}
				if (image != 0) {
					addImage(fromNumber(uid), image);
				}
				break;
			}
			case 9: // category record is ignored
				break;
			case 10:
				unsigned short typeCode;
				PdbUtil::readUnsignedShort(*myStream, typeCode);
				//std::cerr << "type = " << (int)type << "; ";
				//std::cerr << "typeCode = " << typeCode << "\n";
				break;
			case 11: // style sheet record is ignored
				break;
			case 12: // font page record is ignored
				break;
			case 13: // TODO: process tables
			case 14: // TODO: process tables
				break;
			case 15: // multiimage
			{
				unsigned short columns;
				unsigned short rows;
				PdbUtil::readUnsignedShort(*myStream, columns);
				PdbUtil::readUnsignedShort(*myStream, rows);
				PluckerMultiImage *image = new PluckerMultiImage(rows, columns, model().imageMap());
				for (int i = 0; i < size / 2 - 2; ++i) {
					unsigned short us;
					PdbUtil::readUnsignedShort(*myStream, us);
					image->addId(fromNumber(us));
				}
				addImage(fromNumber(uid), image);
				break;
			}
			default:
				//std::cerr << "type = " << (int)type << "\n";
				break;
		}
	}
}
void PluckerBookReader::processTextFunction(char *ptr) {
	switch ((unsigned char)*ptr) {
		case 0x08:
			safeAddControl(INTERNAL_HYPERLINK, false);
			break;
		case 0x0A:
			safeAddHyperlinkControl(fromNumber(twoBytes(ptr + 1)));
			break;
		case 0x0C:
		{
			int sectionNum = twoBytes(ptr + 1);
			int paragraphNum = twoBytes(ptr + 3);
			safeAddHyperlinkControl(fromNumber(sectionNum) + '#' + fromNumber(paragraphNum));
			myReferencedParagraphs.insert(std::pair<int,int>(sectionNum, paragraphNum));
			break;
		}
		case 0x11:
			changeFont((FontType)*(ptr + 1));
			break;
		case 0x1A:
			safeBeginParagraph();
			addImageReference(fromNumber(twoBytes(ptr + 1)));
			break;
		case 0x22:
			if (!myParagraphStarted) {
				if (myForcedEntry == 0) {
					myForcedEntry = new ZLTextForcedControlEntry();
				}
				myForcedEntry->setLeftIndent(*(ptr + 1));
				myForcedEntry->setRightIndent(*(ptr + 2));
			}
			break;
		case 0x29:
			if (!myParagraphStarted) {
				if (myForcedEntry == 0) {
					myForcedEntry = new ZLTextForcedControlEntry();
				}
				switch (*(ptr + 1)) {
					case 0: myForcedEntry->setAlignmentType(ALIGN_LEFT); break;
					case 1: myForcedEntry->setAlignmentType(ALIGN_RIGHT); break;
					case 2: myForcedEntry->setAlignmentType(ALIGN_CENTER); break;
					case 3: myForcedEntry->setAlignmentType(ALIGN_JUSTIFY); break;
				}
			}
			break;
		case 0x33: // just break line instead of horizontal rule (TODO: draw horizontal rule?)
			safeEndParagraph();
			break;
		case 0x38:
			safeEndParagraph();
			break;
		case 0x40: 
			safeAddControl(EMPHASIS, true);
			break;
		case 0x48:
			safeAddControl(EMPHASIS, false);
			break;
		case 0x53: // color setting is ignored
			break;
		case 0x5C:
			addImageReference(fromNumber(twoBytes(ptr + 3)));
			break;
		case 0x60: // underlined text is ignored
			break;
		case 0x68: // underlined text is ignored
			break;
		case 0x70: // strike-through text is ignored
			break;
		case 0x78: // strike-through text is ignored
			break;
		case 0x83: 
		{
			char utf8[4];
			int len = ZLUnicodeUtil::ucs2ToUtf8(utf8, twoBytes(ptr + 2));
			safeBeginParagraph();
			addData(std::string(utf8, len));
			myBufferIsEmpty = false;
			myBytesToSkip = *(ptr + 1);
			break;
		}
		case 0x85: // TODO: process 4-byte unicode character
			break;
		case 0x8E: // custom font operations are ignored
		case 0x8C:
		case 0x8A:
		case 0x88:
			break;
		case 0x90: // TODO: add table processing
		case 0x92: // TODO: process table
		case 0x97: // TODO: process table
			break;
		default: // this should be impossible
			//std::cerr << "Oops... function #" << (int)(unsigned char)*ptr << "\n";
			break;
	}
}