コード例 #1
0
void
BepdfApplication::UpdateFileAttributes(PDFDoc *doc, entry_ref *ref) {
	BNode node(ref);
	if (node.InitCheck() != B_OK) return;

	const bool force_overwrite = (modifiers() & B_COMMAND_KEY) == B_COMMAND_KEY;

	if (force_overwrite) {
		for (int i = 0; gAttrInfo[i].name; i++) {
			node.RemoveAttr(gAttrInfo[i].name);
		}
	}

	int32 pages = (int32)doc->getNumPages();
	UpdateAttr(node, "META:pages", B_INT32_TYPE, 0, &pages, sizeof(int32));
	bool b = doc->isLinearized();
	UpdateAttr(node, "PDF:linearized", B_BOOL_TYPE, 0, &b, sizeof(b));
	double d = doc->getPDFVersion();
	UpdateAttr(node, "PDF:version", B_DOUBLE_TYPE, 0, &d, sizeof(d));

	Object obj;
	if (doc->getDocInfo(&obj) && obj.isDict()) {
		Dict *dict = obj.getDict();
		for (int i = 0; gAttrInfo[i].name; i++) {
			time_t time;
			if (gAttrInfo[i].pdf_name == NULL) continue;
			BString *s = FileInfoWindow::GetProperty(dict, gAttrInfo[i].pdf_name, &time);
			if (s) {
				if (gAttrInfo[i].type_code == B_TIME_TYPE) {
					if (time != 0) {
						UpdateAttr(node, gAttrInfo[i].name, B_TIME_TYPE, 0, &time, sizeof(time));
					}
				} else {
					UpdateAttr(node, gAttrInfo[i].name, B_STRING_TYPE, 0, (void*)s->String(), s->Length()+1);
				}
				delete s;
			}
		}
	}
	obj.free();
}
コード例 #2
0
//
// parses format and (via UpdateAttr and convert) outputs data
void ydpDictionary::ParseRTF(void) {
	char *def = curDefinition;
	int level=0, attr=0, attrs[16], phon;

	newline_=0; newattr=0; newphon=0;

	textlen=0;
	outputView->SetText("");

	while(*def) {
		switch(*def) {
			case '{':
				if (level<16) attrs[level++] = attr;
				break;
			case '\\':
				def = ParseToken(def);
				UpdateAttr(attr);
				attr = newattr;
				break;
			case '}':
				newattr = attrs[--level];
				UpdateAttr(attr);
				break;
			default:
				line += *def;
				break;
		}
		def++;
		if (newline_) {
			if (newattr & A_MARGIN) {
				line.Prepend("\t\t",2);
			}
			line.Append("\n",1);
			UpdateAttr(attr);
			newline_ = 0;
		}
		attr = newattr;
		phon = newphon;
	}
	UpdateAttr(attr);
}