Beispiel #1
0
bool MyDouBan::Parse( const CString &strJson, JSON_INFO &tJsonInfo )
{
	string strJ = (LPCTSTR)strJson;
	
	size_t index = 0;
	
	strJ = strJ.substr(1, strJ.length()-2);
	
	//查询 此次返回的图书数量
	strJ = strJ.substr(8);
	index = strJ.find(',');
	string strValue = strJ.substr(0, index);
	strJ = strJ.substr(index);
	
	tJsonInfo.m_nCount = atoi(strValue.c_str());
	
	//查询 所获结果在全部结果中的偏移值
	strJ = strJ.substr(9);
	index = strJ.find(',');
	strValue = strJ.substr(0, index);
	strJ = strJ.substr(index);
	tJsonInfo.m_nOffset = atoi(strValue.c_str());
	
	//查询 全部书目条数
	strJ = strJ.substr(9);
	index = strJ.find(',');
	strValue = strJ.substr(0, index);
	strJ = strJ.substr(index);
	tJsonInfo.m_nTotal = atoi(strValue.c_str());
	
	//如果没有获取到书目,则直接返回
	if (0 == tJsonInfo.m_nCount ||
		0 == tJsonInfo.m_nTotal)
	{
		return true;
	}
	
	//将表示书目的Json字符串按每本书分割到字符串数组中
	strJ = strJ.substr(11, strJ.length()-12);
	CStringArray sarrBooks;
	ApiSplitToArray(sarrBooks, strJ.c_str(), "\"rating\":", TRUE, 1);
	int iCount = sarrBooks.GetSize();
	if (0 == iCount)
	{
		return false;
	}
	
	for (int i=0; i<iCount; ++i)
	{
		BOOK book;
		if (GetBookInfo(sarrBooks.GetAt(i), book))
		{
			tJsonInfo.m_lsBooks.push_front(book);
		}
	}
	return true;	
}
Beispiel #2
0
void PrepareActiveContent(int opentoc)
{
	if (m_TOC.GetHeader() == NULL)
	{
		bookinfo *bi;
		bi = GetBookInfo(FileName);

		if (bi != NULL)
		{
			m_TOC.SetHeaderName((char *)bi->title);
			if (strrchr(FileName, '/') != NULL)
			{
				m_TOC.SetFileName(strrchr(FileName, '/') + 1);
			}
			else
			{
				m_TOC.SetFileName(FileName);
			}
//			m_TOC.SetFileName((char *)bi->filename);
			m_TOC.SetFilePath((char *)FileName);
#ifdef SYNOPSISV2
			m_TOC.SetVersion(2);
#endif
			m_TOC.SetReaderName("P");
			m_TOC.LoadTOC();
		}
	}

	if (m_TOC.GetHeader() == NULL)
	{
		int i;

		if (toclen == 0)
		{
			if (opentoc == 1)
				Message(ICON_INFORMATION, "PDF Viewer", "@No_contents", 2000);
		}

		for (i=0; i<toclen; i++)
		{
			Content = new SynopsisContent(TOC[i].level, (long long)position_to_page(TOC[i].position) << 40, TOC[i].text);
			m_TOC.AddTOCItem(Content);
		}
	}
}
Beispiel #3
0
int main(int argc, char** argv)
{
        argc_main = argc;
        argv_main = argv;
	SplashColor paperColor;
	GooString* filename, *password;
	char* spwd;
	FILE* f = NULL;
	bookinfo* bi;
	char buf[1024];
	int i;

	mkdir(CACHEDIR, 0777);
	chmod(CACHEDIR, 0777);

	spwd = GetDeviceKey();

	if (setgid(102) != 0) fprintf(stderr, "warning: cannot set gid\n");
	if (setuid(102) != 0) fprintf(stderr, "warning: cannot set uid\n");

	if (spwd)
	{
		//fprintf(stderr, "password: %s\n", spwd);
		password = new GooString(spwd);
	}
	else
	{
		fprintf(stderr, "warning: cannot read password\n");
		password = NULL;
	}

	OpenScreen();

	signal(SIGFPE, sigfpe_handler);
	signal(SIGSEGV, sigsegv_handler);

	clock_left = GetThemeInt("panel.clockleft", 0);
	bmk_flag = GetResource("bmk_flag", NULL);

	if (argc < 2)
	{
		Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000);
		return 0;
	}

	OriginalName = FileName = argv[1];
	bi = GetBookInfo(FileName);
	if (bi->title) book_title = strdup(bi->title);

	// read config file
	globalParams = new GlobalParams();

	globalParams->setEnableFreeType("yes");
	globalParams->setAntialias((char*)(ivstate.antialiasing ? "yes" : "no"));
	globalParams->setVectorAntialias("no");

	filename = new GooString(FileName);
	doc = new PDFDoc(filename, NULL, NULL);
	if (!doc->isOk())
	{
		int err = doc->getErrorCode();
		delete doc;
		if (err == 4)   // encrypted file
		{
			filename = new GooString(FileName);
			doc = new PDFDoc(filename, NULL, password);
			if (!doc->isOk())
			{
				delete doc;
				spwd = query_password();
				password = new GooString(spwd);
				filename = new GooString(FileName);
				doc = new PDFDoc(filename, NULL, password);
				if (!doc->isOk())
				{
					Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000);
					return 0;
				}
			}
		}
		else
		{
			Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000);
			return 0;
		}
	}

	npages = doc->getNumPages();
	paperColor[0] = 255;
	paperColor[1] = 255;
	paperColor[2] = 255;
	splashOut = new MySplashOutputDev(USE4 ? splashModeMono4 : splashModeMono8, 4, gFalse, paperColor);
	splashOut->startDoc(doc->getXRef());

	Outline* outline = doc->getOutline();
	if (outline && outline->getItems())
	{

		GooList* items = outline->getItems();
		if (items->getLength() == 1)
		{
			OutlineItem* first = (OutlineItem*)items->get(0);
			first->open();
			items = first->getKids();
			update_toc(items, 0);
			first->close();
		}
		else if (items->getLength() > 1)
		{
			update_toc(items, 0);
		}

	}

	DataFile = GetAssociatedFile(FileName, 0);
	f = fopen(DataFile, "rb");
	if (f == NULL || fread(&docstate, 1, sizeof(tdocstate), f) != sizeof(tdocstate) || docstate.magic != 0x9751)
	{
		docstate.magic = 0x9751;
		docstate.page = 1;
		docstate.offx = 0;
		docstate.offy = 0;
		docstate.scale = 100;
		docstate.rscale = 150;
		docstate.orient = 0;
		docstate.nbmk = 0;
	}
	if (f != NULL) fclose(f);

	cpage = docstate.page;
	subpage = docstate.subpage;
	offx = docstate.offx;
	offy = docstate.offy;
	if (docstate.scale == 0)
	{
		scale = get_fit_scale();
		ScaleZoomType = ZoomTypeFitWidth;
	}
	else
	{
		scale = docstate.scale;
	}
	rscale = docstate.rscale;
	reflow_mode = (docstate.orient & 0x80) ? 1 : 0;

	gcfg = GetGlobalConfig();
//	ko = ReadInt(gcfg, "keeporient", 0);
	ko = -1;
	if (GetGlobalOrientation() == -1 || ko == 0)
	{
		orient = GetOrientation();
	}
	else
	{
		orient = docstate.orient & 0x7f;
		SetOrientation(orient);
	}

	if (argc >= 3)
	{
		if (argv[2][0] == '=')
		{
#ifdef USESYNOPSIS
			long long position;
			TSynopsisItem::PositionToLong(argv[2] + 1, &position);
			cpage = position_to_page(position >> 40);
#else
//			cpage = atoi(position_to_page(argv[2] + 1));
			cpage = atoi(argv[2] + 1);
#endif
		}
		else
		{