//.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- DtOptItem::ParseDoubleOpt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- // void DtOptItem::ParseDoubleOpt() { m_Option.m_DoubleValue = wtof(m_Option.m_StrValue.c_str()); if (m_Option.m_DoubleValue<m_MinDouble || m_Option.m_DoubleValue>m_MaxDouble) throw DtOptException(L"Invalid argument for command line option: -%ls", m_Name.c_str()); }
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; }