示例#1
0
/*
    Delete an element by name
 */
static int deleteArrayPropertyByName(Ejs *ejs, EjsArray *ap, EjsName qname)
{
    if (isdigit((uchar) qname.name->value[0])) {
        return deleteArrayProperty(ejs, ap, (int) wtoi(qname.name->value));
    }
    return (ejs->service->potHelpers.deletePropertyByName)(ejs, ap, qname);
}
示例#2
0
//.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- DtOptItem::ParseIntOpt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
//
void  DtOptItem::ParseIntOpt()
{
    if (m_EnumPairs != NULL)
    {
        m_Option.ParseEnum(m_EnumPairs, m_Name);
    } else {
        m_Option.m_IntValue = wtoi(m_Option.m_StrValue.c_str());
        if (m_Option.m_IntValue<m_MinInt || m_Option.m_IntValue>m_MaxInt)
            throw DtOptException(L"Invalid argument for command line option: -%ls", 
                                                                          m_Name.c_str());
    }
}
示例#3
0
文件: Main.cpp 项目: darkfall/gac
	Ptr<text::DocumentModel> BuildDocumentModel(const WString& fileName, List<Ptr<GifRun>>& animations)
	{
		HDC dc=CreateCompatibleDC(NULL);
		int dpi=GetDeviceCaps(dc, LOGPIXELSY);
		DeleteDC(dc);
		Ptr<text::DocumentModel> document=new text::DocumentModel;

		WString rawDocument;
		{
			FileStream fileStream(fileName, FileStream::ReadOnly);
			BomDecoder decoder;
			DecoderStream decoderStream(fileStream, decoder);
			StreamReader reader(decoderStream);
			rawDocument=reader.ReadToEnd();
		}

		WString regexTag_s=L"<(<tag>s)>(<font>[^:]+):(<bold>[^:]+):(<color>[^:]+):(<size>[^:]+):(<text>/.*?)<//s>";
		WString regexTag_i=L"<(<tag>i)>(<cx>[^:]+),(<cy>[^:]+):(<b>[^:]+):(<file>/.*?)<//i>";
		WString regexTag_p=L"<(<tag>p)//>";
		Regex regexTag(regexTag_s+L"|"+regexTag_i+L"|"+regexTag_p);
		Regex regexLine(L"\r\n");
		RegexMatch::List matches;
		regexTag.Search(rawDocument, matches);

		Ptr<text::DocumentParagraph> paragraph=0;
		Ptr<text::DocumentLine> line=0;
		
		for(int i=0;i<matches.Count();i++)
		{
			Ptr<RegexMatch> match=matches[i];
			if(match->Groups()[L"tag"].Get(0).Value()==L"p")
			{
				paragraph=0;
				line=0;
			}
			else if(match->Groups()[L"tag"].Get(0).Value()==L"i")
			{
				int cx=wtoi(match->Groups()[L"cx"].Get(0).Value());
				int cy=wtoi(match->Groups()[L"cy"].Get(0).Value());
				int b=wtoi(match->Groups()[L"b"].Get(0).Value());
				WString file=match->Groups()[L"file"].Get(0).Value();

				if(!paragraph)
				{
					paragraph=new text::DocumentParagraph;
					document->paragraphs.Add(paragraph);
					line=0;
				}
				if(!line)
				{
					line=new text::DocumentLine;
					paragraph->lines.Add(line);
				}

				Ptr<text::DocumentImageRun> run=new text::DocumentImageRun;
				run->size=Size(cx, cy);
				run->baseline=b;
				run->image=GetCurrentController()->ImageService()->CreateImageFromFile(L"..\\Resources\\"+file);
				run->frameIndex=0;
				line->runs.Add(run);

				if(run->image->GetFrameCount()>1)
				{
					Ptr<GifRun> gifRun=new GifRun;
					gifRun->imageRun=run;
					gifRun->paragraphIndex=document->paragraphs.Count()-1;
					animations.Add(gifRun);
				}
			}
			else if(match->Groups()[L"tag"].Get(0).Value()==L"s")
			{
				FontProperties fontStyle;
				Color fontColor;
				RegexMatch::List lines;
				{
					WString font=match->Groups()[L"font"].Get(0).Value();
					WString bold=match->Groups()[L"bold"].Get(0).Value();
					WString color=match->Groups()[L"color"].Get(0).Value();
					WString size=match->Groups()[L"size"].Get(0).Value();
					WString text=match->Groups()[L"text"].Get(0).Value();

					fontStyle.fontFamily=font;
					fontStyle.bold=bold==L"true";
					fontStyle.size=(int)(wtof(size)*dpi/72);
					fontColor=ConvertColor(color);
					regexLine.Split(text, true, lines);
				}

				for(int j=0;j<lines.Count();j++)
				{
					WString lineText=lines[j]->Result().Value();
					if(!paragraph)
					{
						paragraph=new text::DocumentParagraph;
						document->paragraphs.Add(paragraph);
						line=0;
					}
					if(!line || j>0)
					{
						line=new text::DocumentLine;
						paragraph->lines.Add(line);
					}

					Ptr<text::DocumentTextRun> run=new text::DocumentTextRun;
					run->style=fontStyle;
					run->color=fontColor;
					run->text=lineText;
					line->runs.Add(run);
				}
			}
		}

		return document;
	}