bool RenderSVGImage::updateImageViewport() { FloatRect oldBoundaries = m_objectBoundingBox; bool updatedViewport = false; SVGLengthContext lengthContext(&imageElement()); m_objectBoundingBox = FloatRect(imageElement().x().value(lengthContext), imageElement().y().value(lengthContext), imageElement().width().value(lengthContext), imageElement().height().value(lengthContext)); // Images with preserveAspectRatio=none should force non-uniform scaling. This can be achieved // by setting the image's container size to its intrinsic size. // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute. if (imageElement().preserveAspectRatio().align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) { if (CachedImage* cachedImage = imageResource().cachedImage()) { LayoutSize intrinsicSize = cachedImage->imageSizeForRenderer(0, style().effectiveZoom()); if (intrinsicSize != imageResource().imageSize(style().effectiveZoom())) { imageResource().setContainerSizeForRenderer(roundedIntSize(intrinsicSize)); updatedViewport = true; } } } if (oldBoundaries != m_objectBoundingBox) { if (!updatedViewport) imageResource().setContainerSizeForRenderer(enclosingIntRect(m_objectBoundingBox).size()); updatedViewport = true; m_needsBoundariesUpdate = true; } return updatedViewport; }
bool RenderSVGImage::updateImageViewport() { FloatRect oldBoundaries = m_objectBoundingBox; SVGLengthContext lengthContext(&imageElement()); m_objectBoundingBox = FloatRect(imageElement().x().value(lengthContext), imageElement().y().value(lengthContext), imageElement().width().value(lengthContext), imageElement().height().value(lengthContext)); if (oldBoundaries == m_objectBoundingBox) return false; m_imageResource->setContainerSizeForRenderer(enclosingIntRect(m_objectBoundingBox).size()); m_needsBoundariesUpdate = true; return true; }
int main( int argc, char** argv ) { QApplication app( argc, argv ); KDReports::Report report; KDReports::Header& header = report.header( KDReports::FirstPage ); header.addElement( KDReports::TextElement( "A tall image made to fit into the page" ) ); KDReports::Header& header2 = report.header( KDReports::EvenPages ); header2.addElement( KDReports::TextElement( "A wide image made to fit into the page" ) ); KDReports::Footer& footer = report.footer(); footer.addElement( KDReports::TextElement( "Page" ), Qt::AlignRight ); footer.addInlineElement( KDReports::TextElement( " " ) ); footer.addVariable( KDReports::PageNumber ); footer.addInlineElement( KDReports::TextElement( "/" ) ); footer.addVariable( KDReports::PageCount ); KDReports::ImageElement imageElement( QPixmap( ":/imageTall.jpg" ) ); imageElement.setFitToPage(); report.addElement( imageElement ); KDReports::ImageElement imageElement2( QPixmap( ":/image.jpg" ) ); imageElement2.setFitToPage(); report.addElement( imageElement2 ); KDReports::PreviewDialog preview( &report ); return preview.exec(); }
void RenderSVGImage::layout() { StackStats::LayoutCheckPoint layoutCheckPoint; ASSERT(needsLayout()); LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(*this) && selfNeedsLayout()); updateImageViewport(); bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundariesUpdate; if (m_needsTransformUpdate) { m_localTransform = imageElement().animatedLocalTransform(); m_needsTransformUpdate = false; } if (m_needsBoundariesUpdate) { m_repaintBoundingBoxExcludingShadow = m_objectBoundingBox; SVGRenderSupport::intersectRepaintRectWithResources(*this, m_repaintBoundingBoxExcludingShadow); m_repaintBoundingBox = m_repaintBoundingBoxExcludingShadow; SVGRenderSupport::intersectRepaintRectWithShadows(*this, m_repaintBoundingBox); m_needsBoundariesUpdate = false; } // Invalidate all resources of this client if our layout changed. if (everHadLayout() && selfNeedsLayout()) SVGResourcesCache::clientLayoutChanged(*this); // If our bounds changed, notify the parents. if (transformOrBoundariesUpdate) RenderSVGModelObject::setNeedsBoundariesUpdate(); repainter.repaintAfterLayout(); clearNeedsLayout(); }
bool HTMLAreaElement::rendererIsFocusable() const { HTMLImageElement* image = imageElement(); if (!image || !image->renderer() || image->renderer()->style()->visibility() != VISIBLE) return false; return supportsFocus() && Element::tabIndex() >= 0; }
virtual void run() { // Create a report KDReports::Report report; report.setWatermarkImage( QImage( ":/background.jpg" ) ); report.setWatermarkText( QString() ); KDReports::ImageElement imageElement(QImage(":/logo.png")); report.header().addElement(imageElement); // Add a text element for the title KDReports::TextElement titleElement( QObject::tr( "KD Reports Hello world example" ) ); titleElement.setPointSize( 18 ); report.addElement( titleElement, Qt::AlignHCenter ); // A bit of spacing (10 mm) report.addVerticalSpacing( 10 ); // Add another text element, demonstrating "<<" operator KDReports::TextElement textElement; textElement << QObject::tr( "This is a sample report produced with KD Reports." ); textElement << "\n"; textElement << QObject::tr( "Klarälvdalens Datakonsult AB, Platform-independent software solutions" ); textElement << "\n"; report.addElement( textElement ); // Create a table model, which will be used by the table element HelloWorldTableModel tableModel; // A bit of spacing (10 mm) report.addVerticalSpacing( 10 ); // Add an "auto table" (a table that shows the contents of a model) KDReports::AutoTableElement tableElement( &tableModel ); tableElement.setBorder( 1 ); report.addElement( tableElement ); // Add many paragraphs, to demonstrate page breaking for ( int i = 1; i < 100 ; ++i ) { report.addElement( KDReports::HtmlElement( QString::fromLatin1( "<b>Customer</b> <em>%1</em>" ).arg(i) ), Qt::AlignLeft ); report.addInlineElement( KDReports::TextElement( " - 2006" ) ); } // Add a page break report.addPageBreak(); report.addElement( KDReports::TextElement( "This is the last page" ) ); // To export to an image file: //qDebug() << "Exporting to output.png"; report.exportToImage( QSize(200, 1200), "output.png", "PNG" ); // deleted by main() below // To export to a PDF file: //qDebug() << "Exporting to output.pdf"; report.exportToFile( "output.pdf" ); // deleted by main() below }
void RenderSVGImage::paintForeground(PaintInfo& paintInfo) { RefPtr<Image> image = imageResource().image(); FloatRect destRect = m_objectBoundingBox; FloatRect srcRect(0, 0, image->width(), image->height()); imageElement().preserveAspectRatio().transformRect(destRect, srcRect); paintInfo.context->drawImage(image.get(), ColorSpaceDeviceRGB, destRect, srcRect); }
/** * Content policy logic for compose windows * */ void nsMsgContentPolicy::ComposeShouldLoad(nsIMsgCompose *aMsgCompose, nsISupports *aRequestingContext, nsIURI *aContentLocation, PRInt16 *aDecision) { NS_PRECONDITION(*aDecision == nsIContentPolicy::REJECT_REQUEST, "ComposeShouldLoad expects default decision to be reject!"); nsresult rv; nsCString originalMsgURI; rv = aMsgCompose->GetOriginalMsgURI(getter_Copies(originalMsgURI)); NS_ENSURE_SUCCESS(rv, ); MSG_ComposeType composeType; rv = aMsgCompose->GetType(&composeType); NS_ENSURE_SUCCESS(rv, ); // Only allow remote content for new mail compositions or mailto // Block remote content for all other types (drafts, templates, forwards, replies, etc) // unless there is an associated msgHdr which allows the load, or unless the image is being // added by the user and not the quoted message content... if (composeType == nsIMsgCompType::New || composeType == nsIMsgCompType::MailToUrl) *aDecision = nsIContentPolicy::ACCEPT; else if (!originalMsgURI.IsEmpty()) { nsCOMPtr<nsIMsgDBHdr> msgHdr; rv = GetMsgDBHdrFromURI(originalMsgURI.get(), getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, ); *aDecision = ShouldAcceptRemoteContentForMsgHdr(msgHdr, nsnull, aContentLocation); // Special case image elements. When replying to a message, we want to allow // the user to add remote images to the message. But we don't want remote // images that are a part of the quoted content to load. Fortunately, after // the quoted message has been inserted into the document, mail compose // flags remote content elements that came from the original message with a // moz-do-not-send attribute. if (*aDecision == nsIContentPolicy::REJECT_REQUEST) { bool insertingQuotedContent = true; aMsgCompose->GetInsertingQuotedContent(&insertingQuotedContent); nsCOMPtr<nsIDOMHTMLImageElement> imageElement(do_QueryInterface(aRequestingContext)); if (!insertingQuotedContent && imageElement) { bool doNotSendAttrib; if (NS_SUCCEEDED(imageElement->HasAttribute(NS_LITERAL_STRING("moz-do-not-send"), &doNotSendAttrib)) && !doNotSendAttrib) *aDecision = nsIContentPolicy::ACCEPT; } } }
void RenderSVGImage::paintForeground(PaintInfo& paintInfo) { RefPtr<Image> image = imageResource().image(); if (!image) return; FloatRect destRect = m_objectBoundingBox; FloatRect srcRect(0, 0, image->width(), image->height()); imageElement().preserveAspectRatio().transformRect(destRect, srcRect); paintInfo.context().drawImage(*image, destRect, srcRect); }
bool KDReports::XmlParser::processNode( const QDomNode& node, KDReports::ReportBuilder* builder, bool inHeader, bool inFooter ) { // Loop over elements for ( QDomElement element = node.firstChildElement() ; !element.isNull(); element = element.nextSiblingElement() ) { if ( testForErrorAndFillErrorDetails() ) return false; const QString name = element.tagName(); if( name == QLatin1String( "text" ) ) { // Handle <text> element KDReports::TextElement textElement; QString id; const QString text = extractText( element, &id, m_report->d->m_currentModel, m_report->d->m_currentRow ); textElement.setText( text ); textElement.setId( id ); const QColor bgColor = KDReports::XmlHelper::readBackground( element ); if( bgColor.isValid() ) textElement.setBackground( bgColor ); if( element.hasAttribute( QLatin1String( "pointsize" ) ) ) { const int pointSize = element.attribute( QLatin1String( "pointsize" ) ).toInt(); if( pointSize ) textElement.setPointSize( pointSize ); } if( element.hasAttribute( QLatin1String( "color" ) ) ) { const QString name = element.attribute( QLatin1String( "color" ) ); textElement.setTextColor( QColor( name ) ); } if( element.hasAttribute( QLatin1String( "font" ) ) ) { textElement.setFontFamily( element.attribute( QLatin1String( "font" ) ) ); } if( element.hasAttribute( QLatin1String( "bold" ) ) ) { bool bold = false; if( element.attribute( QLatin1String( "bold" ) ) == QLatin1String( "true" ) ) bold = true; textElement.setBold( bold ); } if( element.hasAttribute( QLatin1String( "italic" ) ) ) { bool italic = false; if( element.attribute( QLatin1String( "italic" ) ) == QLatin1String( "true" ) ) italic = true; textElement.setItalic( italic ); } if( element.hasAttribute( QLatin1String( "strikeout" ) ) ) { bool strikeOut = false; if( element.attribute( QLatin1String( "strikeout" ) ) == QLatin1String( "true" ) ) strikeOut = true; textElement.setStrikeOut( strikeOut ); } if( element.hasAttribute( QLatin1String( "underline" ) ) ) { bool underline = false; if( element.attribute( QLatin1String( "underline" ) ) == QLatin1String( "true" ) ) underline = true; textElement.setUnderline( underline ); } const QString oldId = textElement.id(); if ( m_xmlElementHandler && !m_xmlElementHandler->textElement( textElement, element ) ) continue; if ( textElement.id() != oldId ) { // The handler modified the text element's id, look up the value again. const QHash<QString, QString>::const_iterator it = m_textValues.constFind( textElement.id() ); if ( it != m_textValues.constEnd() ) { textElement.setText( *it ); } } if ( !builder ) { error( QObject::tr( "<text> is only supported in WordProcessing mode" ) ); } else { if( element.hasAttribute( QLatin1String( "inline" ) ) ) { builder->addInlineElementPublic( textElement ); } else { Qt::AlignmentFlag alignment = Qt::AlignLeft; if( element.hasAttribute( QLatin1String( "alignment" ) ) ) alignment = KDReports::XmlHelper::stringToAlignment( element.attribute( QLatin1String( "alignment" ) ) ); const QColor bgColor = KDReports::XmlHelper::readColor( element, "paragraph-background" ); builder->addBlockElementPublic( textElement, alignment, bgColor ); } } } else if( name == QLatin1String( "html" ) ) { // Handle <html> element KDReports::HtmlElement htmlElement; QString id; const QString text = extractText( element, &id ); htmlElement.setHtml( text ); htmlElement.setId( id ); QColor bgColor = KDReports::XmlHelper::readBackground( element ); if( bgColor.isValid() ) htmlElement.setBackground( bgColor ); const QString oldId = htmlElement.id(); if ( m_xmlElementHandler && !m_xmlElementHandler->htmlElement( htmlElement, element ) ) continue; if ( htmlElement.id() != oldId ) { // The handler modified the text element's id, look up the value again. const QHash<QString, QString>::const_iterator it = m_textValues.constFind( htmlElement.id() ); if ( it != m_textValues.constEnd() ) { htmlElement.setHtml( *it ); } } addElement( htmlElement, builder, element ); } else if ( name == QLatin1String( "tabs" ) ) { if ( !builder ) { error( QObject::tr( "<tabs> is only supported in WordProcessing mode" ) ); } else { parseTabs( builder, element ); } } else if ( name == QLatin1String( "paragraph-margins" ) ) { if ( !builder ) { error( QObject::tr( "<paragraph-margins> is only supported in WordProcessing mode" ) ); } else { parseParagraphMargins( builder, element ); } } else if( name == QLatin1String( "hr" ) ) { // Handle <hr> element KDReports::HtmlElement htmlElement; htmlElement.setHtml( QString::fromLatin1("<hr>") ); if ( m_xmlElementHandler && !m_xmlElementHandler->htmlElement( htmlElement, element ) ) continue; addElement( htmlElement, builder, element ); } else if( name == QLatin1String( "vspace" ) ) { // Handle <vspace> element if( !element.hasAttribute( QLatin1String( "size" ) ) ) continue; // size attribute is mandatory for VSpace int size = element.attribute( QLatin1String( "size" ) ).toInt(); if ( !builder ) { error( QObject::tr( "<vspace> is only supported in WordProcessing mode" ) ); } else { if( builder != m_report->d->builder() ) { error( QObject::tr("<vspace> not allowed in headers, footers, or table cells") ); return false; } } XmlElementHandlerV2* v2 = dynamic_cast<XmlElementHandlerV2 *>(m_xmlElementHandler); if (v2 && !v2->vspace(size, element)) continue; m_report->addVerticalSpacing( size ); } else if( name == QLatin1String( "table" ) ) { // Handle <table> element const QString model = element.attribute( QLatin1String( "model" ) ); if ( model.isEmpty() ) { if ( !builder ) { error( QObject::tr( "<table> without a model is only supported in WordProcessing mode" ) ); continue; } KDReports::TableElement tableElement; const int headerRowCount = element.attribute( QLatin1String( "headerRowCount" ) ).toInt(); // default 0 tableElement.setHeaderRowCount( headerRowCount ); if ( element.hasAttribute( QLatin1String( "cellpadding" ) ) ) tableElement.setPadding( element.attribute( QLatin1String( "cellpadding" ) ).toInt() ); parseCommonTableAttributes( tableElement, element ); if ( m_xmlElementHandler && !m_xmlElementHandler->startTableElement( tableElement, element ) ) continue; if ( !parseTableContents( tableElement, element, *builder, inHeader, inFooter ) ) return false; if ( m_xmlElementHandler && !m_xmlElementHandler->endTableElement( tableElement, element ) ) continue; addElement( tableElement, builder, element ); } else { KDReports::AutoTableElement tableElement( model ); if( element.attribute( QLatin1String( "verticalHeaderVisible" ) ) == QLatin1String( "false" ) ) tableElement.setVerticalHeaderVisible(false); if( element.attribute( QLatin1String( "horizontalHeaderVisible" ) ) == QLatin1String( "false" ) ) tableElement.setHorizontalHeaderVisible(false); QColor headerBgColor = KDReports::XmlHelper::readColor( element, "header-background" ); if ( headerBgColor.isValid() ) tableElement.setHeaderBackground( headerBgColor ); parseCommonTableAttributes( tableElement, element ); if ( m_xmlElementHandler && !m_xmlElementHandler->autoTableElement( tableElement, element ) ) continue; if ( m_report->reportMode() == Report::SpreadSheet ) { m_report->mainTable()->setAutoTableElement( tableElement ); } else { addElement( tableElement, builder, element ); } } } else if( name == QLatin1String( "chart" ) ) { // Handle <chart> element KDReports::ChartElement chartElement( element.attribute( QLatin1String( "model" ) ) ); QColor bgColor = KDReports::XmlHelper::readBackground( element ); if( bgColor.isValid() ) chartElement.setBackground( bgColor ); int width = 100, height = 100; Unit unit = Millimeters; if( element.hasAttribute( QLatin1String( "width" ) ) ) { QString str = element.attribute( QLatin1String( "width" ) ); if ( str.endsWith( QLatin1Char('%') ) ) { str.chop( 1 ); unit = Percent; } width = str.toInt(); } if( element.hasAttribute( QLatin1String( "height" ) ) ) { QString str = element.attribute( QLatin1String( "height" ) ); if ( str.endsWith( QLatin1Char('%') ) ) { str.chop( 1 ); unit = Percent; } height = str.toInt(); } chartElement.setSize( width, height, unit ); if ( m_xmlElementHandler && !m_xmlElementHandler->chartElement( chartElement, element ) ) continue; addElement( chartElement, builder, element ); } else if( name == QLatin1String( "image" ) ) { // Handle <image> element QString id; QImage image = extractImage( element, &id ); KDReports::ImageElement imageElement( image ); imageElement.setId(id); if( element.hasAttribute( QLatin1String( "width" ) ) ) { QString widthStr = element.attribute( QLatin1String( "width" ) ); if ( widthStr.endsWith( QLatin1Char('%') ) ) { widthStr.truncate( widthStr.length() - 1 ); imageElement.setWidth( widthStr.toInt(), KDReports::Percent ); } else { imageElement.setWidth( widthStr.toInt() ); } } else if( element.hasAttribute( QLatin1String( "height" ) ) ) { // mutually exclusive with "width"! QString heightStr = element.attribute( QLatin1String( "height" ) ); if ( heightStr.endsWith( QLatin1Char('%') ) ) { heightStr.truncate( heightStr.length() - 1 ); imageElement.setHeight( heightStr.toInt(), KDReports::Percent ); } else { imageElement.setHeight( heightStr.toInt() ); } } else if ( element.hasAttribute( QLatin1String( "fitToPage" ) ) ) { imageElement.setFitToPage(); } if ( m_xmlElementHandler && !m_xmlElementHandler->imageElement( imageElement, element ) ) continue; addElement( imageElement, builder, element ); } else if( name == QLatin1String( "header" ) ) { const KDReports::HeaderLocations loc = KDReports::XmlHelper::parseHeaderLocation( element.attribute( QLatin1String( "location" ) ) ); KDReports::Header& header = m_report->header( loc ); parseHeaderFooterAttribute( header, element ); if ( m_xmlElementHandler && !m_xmlElementHandler->startHeader( header, element ) ) continue; if( !processNode( element, &header.d->m_builder, true, false ) ) return false; if ( m_xmlElementHandler ) m_xmlElementHandler->endHeader( header, element ); } else if( name == QLatin1String( "footer" ) ) { const KDReports::HeaderLocations loc = KDReports::XmlHelper::parseHeaderLocation( element.attribute( QLatin1String( "location" ) ) ); KDReports::Footer& footer = m_report->footer( loc ); parseHeaderFooterAttribute( footer, element ); if ( m_xmlElementHandler && !m_xmlElementHandler->startFooter( footer, element ) ) continue; if( !processNode( element, &footer.d->m_builder, false, true ) ) return false; if ( m_xmlElementHandler ) m_xmlElementHandler->endFooter( footer, element ); } else if( name == QLatin1String( "variable" ) ) { if( !inHeader && !inFooter ) { error( QObject::tr("<variable> tags only allowed in headers and footers") ); return false; } if( !element.hasAttribute( QLatin1String( "type" ) ) ) { error( QObject::tr("<variable> tags must have a 'type' attribute") ); return false; } Q_ASSERT( builder ); if ( builder ) { const QString type = element.attribute( QLatin1String( "type" ) ); KDReports::VariableType vt = KDReports::XmlHelper::stringToVariableType( type ); XmlElementHandlerV2* v2 = dynamic_cast<XmlElementHandlerV2 *>(m_xmlElementHandler); if (v2 && !v2->variable(vt, element)) continue; builder->addVariablePublic( vt ); } } else if ( name == QLatin1String( "page-break" ) ) { if ( m_xmlElementHandler && !m_xmlElementHandler->pageBreak( element ) ) continue; m_report->addPageBreak(); } else if ( name == QLatin1String( "ifdef" ) ) { if ( element.hasAttribute( QLatin1String( "id" ) ) ) { const QString id = element.attribute( QLatin1String( "id" ) ); const bool skip = m_textValues.value( id ).isEmpty(); if( !skip ) { if ( !processNode( element, builder, inHeader, inFooter ) ) return false; } } } else if ( name == QLatin1String( "custom" ) ) { if ( m_xmlElementHandler ) m_xmlElementHandler->customElement( element ); } else if ( name == QLatin1String( "hline" ) ) { KDReports::HLineElement hLineElement; if ( element.hasAttribute( QLatin1String( "thickness" ) ) ) { const double thickness = element.attribute( QLatin1String( "thickness" ) ).toDouble(); hLineElement.setThickness( thickness ); } if ( element.hasAttribute( QLatin1String( "color" ) ) ) { const QColor color = KDReports::XmlHelper::readColor( element, "color" ); hLineElement.setColor( color ); } if ( element.hasAttribute( QLatin1String( "margin" ) ) ) { const int margin = element.attribute( QLatin1String( "margin" ) ).toInt(); hLineElement.setMargin( margin ); } #ifdef KDREPORTS_ALLOW_BINARY_INCOMPATIBILITY if ( m_xmlElementHandler && !m_xmlElementHandler->hLineElement( hLineElement, element ) ) continue; #else XmlElementHandlerV2* v2 = dynamic_cast<XmlElementHandlerV2 *>(m_xmlElementHandler); if (v2 && !v2->hLineElement(hLineElement, element)) continue; #endif addElement( hLineElement, builder, element ); } else { error( QObject::tr( "KDReports::Report::loadFromXML(): Unknown element %1" ).arg( name ) ); } } if ( testForErrorAndFillErrorDetails() ) return false; return true; }
int ConsoleProgram::main(const std::vector<CL_String> &args) { // Setup clanCore: CL_SetupCore setup_core; // Initialize the ClanLib display component CL_SetupDisplay setup_display; // Create a console Window if one does not exist: CL_ConsoleWindow console_window("Console", 80, 600); try { //получение параметра запуска for (std::vector<CL_String>::const_iterator iter_args = args.begin(); iter_args != args.end(); ++iter_args) CL_Console::write_line( *iter_args ); //получение имени директории для сохранения CL_String workDirectoryName; if (args.size() > 1) { //полное имя рабочей директории workDirectoryName = args[1]; //конвертирование из CP-1251 в UTF-8 имени рабочей директории workDirectoryName = decode(workDirectoryName); } else { //получение полного пути к текущему каталогу workDirectoryName = CL_Directory::get_current(); } CL_Console::write_line("workDirectoryName: %1", workDirectoryName); //получение имени последней директории CL_String locationName = CL_PathHelp::remove_trailing_slash(workDirectoryName); locationName = CL_PathHelp::get_filename(locationName); CL_Console::write_line("locationName: %1", locationName); CL_String tempDir = CL_PathHelp::add_trailing_slash(workDirectoryName) + "temp\\"; CL_DirectoryScanner directoryScanner; directoryScanner.scan(tempDir, "*.export"); while (directoryScanner.next()) { //имя обрабатываемого файла CL_String fileName; if (directoryScanner.is_directory()) continue; //получение полного имени файла экспорта fileName = directoryScanner.get_pathname(); //конвертирование из CP-1251 в UTF-8 fileName = decode(fileName); CL_Console::write_line("find: %1", fileName); //открытие XML файла CL_File fileXML; bool is_opened = fileXML.open(fileName); if( !is_opened ) return PrintError( CL_String("Can't open file: ") + fileName ); //Создание объекта DOM парсера CL_DomDocument document(fileXML); //получение root узла CL_DomElement root = document.get_document_element(); if( root.get_local_name() != "resources") { CL_Console::write_line("Root name can't be: %1", root.get_local_name().c_str()); return PrintError(""); } //цикл по потомкам "resources" for (CL_DomNode cur = root.get_first_child(); !cur.is_null(); cur = cur.get_next_sibling()) { //загрузка только спрайтов if (cur.get_node_name() != "sprite") continue; CL_DomElement element = cur.to_element(); //проверка на обязательные параметры if (!element.has_attribute("name")) return PrintError("Error: can't find parametr \"name\""); CL_DomString name = element.get_attribute("name"); int x = element.get_attribute_int("x"); int y = element.get_attribute_int("y"); //добавление спрайта sprites.push_back( S_Sprite(name, CL_Vec2i(x, y) ) ); //цикл по "image" (формирование списка имен файлов) for (CL_DomNode cur_image = cur.get_first_child(); !cur_image.is_null(); cur_image = cur_image.get_next_sibling()) { //загрузка только image if (cur_image.get_node_name() != "image") continue; CL_DomElement element_image = cur_image.to_element(); CL_DomString file = element_image.get_attribute("file"); //конвертирование из CP-1251 в UTF-8 имени файла изображения file = decode(file); //добавление изображения для обработки (sprites.end()-1)->AddImage(file); } //цикл по "frame" (дополнение списка информацией о файле) for (CL_DomNode cur_frame = cur.get_first_child(); !cur_frame.is_null(); cur_frame = cur_frame.get_next_sibling()) { if (cur_frame.get_node_name() != "frame") continue; CL_DomElement element_frame = cur_frame.to_element(); //проверка на обязательные параметры if (!element_frame.has_attribute("nr")) return PrintError("Error: can't find parameter \"nr\""); size_t nr = element_frame.get_attribute_int("nr"); int speed = element_frame.get_attribute_int("speed"); int x_image = element_frame.get_attribute_int("x"); int y_image = element_frame.get_attribute_int("y"); (sprites.end()-1)->SetAnimationsParam(nr, speed, CL_Vec2i(x_image, y_image)); } } fileXML.close(); } //CL_Console::wait_for_key(); // TODO: //проверка на перекрытие ресурсных имен //return PrintError( CL_String("Error: This resourse already exist") ); //декодирование имени спрайта и генерация с декодированием полных имен файлов for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { //CL_Console::write_line("processing: %1 pos = %2 %3", iter_sprites->mName, iter_sprites->mPos.x, iter_sprites->mPos.y); //генерация полного имени файла iter_images->mSourceFullName = CL_PathHelp::make_absolute(tempDir, iter_images->mSourceFileName); //CL_Console::write_line("image: %1 pos = %2 %3", iter_images->mSourceFileName, iter_images->mOffset.x, iter_images->mOffset.y); CL_Console::write_line("image fullname: %1", iter_images->mSourceFullName); } } //CL_Console::wait_for_key(); //загрузка файлов-картинок for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) iter_images->mImage = CL_ImageProviderFactory::load(iter_images->mSourceFullName).to_format(cl_rgba8); //CL_Console::wait_for_key(); //проход по всем спрайтам для определения необходимости разрезки на несколько спрайтов for(T_Sprites::size_type iSprites = 0; iSprites < sprites.size(); ++iSprites) { for(S_Sprite::T_Images::size_type iImages = 0; iImages < sprites[iSprites].mImages.size(); ++iImages) { //определение размеров CL_Size image_size = sprites[iSprites].mImages[iImages].mImage.get_size(); //Определение наличия прозрачности sprites[iSprites].mImages[iImages].mNoTransparent = testAlpha(sprites[iSprites].mImages[iImages].mImage); //высота превышает допустимую if(image_size.height > MAX_HEIGHT) return PrintError( CL_String("Error: image height is more then 1024") ); //ширина превышает допустимую if(image_size.width > MAX_WIDTH) { CL_Console::write_line("scussor: sprites[iSprites].mName: %1", sprites[iSprites].mName); //проверка на то что у этого спрайта один image if(sprites[iSprites].mImages.size() > 1) return PrintError( CL_String("Error: animation size can't be more than MAX_WIDTH*MAX_HEIGHT (1024*1024)") ); //сохранение высоты и ширины int h = image_size.height; int w = image_size.width; //определение кол-ва частей на разрезку int n; //кол-во частей на разрезку for(n = 2; n < 10; ++n) if (w > (n-1)*MAX_WIDTH - 2*(n-2) && w <= (n)*MAX_WIDTH - 2*(n-1)) break; T_Sprites::iterator addedSprite; switch (n) { case 2: //две части //спрайт слева (задание имени и позиции спрайта) addedSprite = sprites.insert( sprites.begin()+iSprites+1, S_Sprite(CL_String(sprites[iSprites].mName)+CL_StringHelp::int_to_text(0), sprites[iSprites].mPos+CL_Vec2i(0, 0) ) ); //создание одного Image в добавленом спрайте addedSprite->AddImage(sprites[iSprites].mImages[iImages].mSourceFileName); //создание изображения (задание зазмеров спрайта) addedSprite->mImages[0].mImage = CL_PixelBuffer(MAX_WIDTH, h, cl_rgba8); //наследование флага отсутствия прозрачности addedSprite->mImages[0].mNoTransparent = sprites[iSprites].mImages[iImages].mNoTransparent; //копирование куска изображения sprites[iSprites].mImages[iImages].mImage.convert(addedSprite->mImages[0].mImage, //(dst Rect, src Rect) CL_Rect(0, 0, MAX_WIDTH, h), CL_Rect(0, 0, MAX_WIDTH, h)); addedSprite->mImages[0].mDeltaGrid.left = 0; addedSprite->mImages[0].mDeltaGrid.right = -1; //спрайт справа (задание имени и позиции спрайта) addedSprite = sprites.insert( sprites.begin()+iSprites+1, S_Sprite(CL_String(sprites[iSprites].mName)+CL_StringHelp::int_to_text(1), sprites[iSprites].mPos+CL_Vec2i(MAX_WIDTH-1, 0) ) ); //создание одного Image в добавленом спрайте addedSprite->AddImage(sprites[iSprites].mImages[iImages].mSourceFileName); //создание изображения (задание зазмеров спрайта) addedSprite->mImages[0].mImage = CL_PixelBuffer(w-MAX_WIDTH+2, h, cl_rgba8); //наследование флага отсутствия прозрачности addedSprite->mImages[0].mNoTransparent = sprites[iSprites].mImages[iImages].mNoTransparent; //копирование куска изображения sprites[iSprites].mImages[iImages].mImage.convert(addedSprite->mImages[0].mImage, //(dst Rect, src Rect) CL_Rect(0, 0, w-MAX_WIDTH+2, h), CL_Rect(MAX_WIDTH-2, 0, w, h)); addedSprite->mImages[0].mDeltaGrid.left = +1; addedSprite->mImages[0].mDeltaGrid.right = -1; break; default: return PrintError( CL_String("Error: scussored on >2 part is't writen by C++ programmer") ); break; } /* //разделение изображения на части int x = 1; int residual = image_size.width; int left, right; int i = 0; do { x -= 1; left = x; x += min(MAX_WIDTH, residual); right = x; residual -= (right-left-1); i++; //добавление куска T_Sprites::iterator addedSprite = sprites.insert( sprites.begin()+iSprites+1, S_Sprite(CL_String(sprites[iSprites].mName)+CL_StringHelp::int_to_text(i), sprites[iSprites].mPos+CL_Vec2i(left, 0) ) ); //создание одного Image в добавленом спрайте addedSprite->AddImage(sprites[iSprites].mImages[iImages].mSourceFileName); //создание изображения addedSprite->mImages[0].mImage = CL_PixelBuffer(right-left, h, cl_rgba8); //наследование флага отсутствия прозрачности addedSprite->mImages[0].mNoTransparent = sprites[iSprites].mImages[iImages].mNoTransparent; //копирование куска изображения sprites[iSprites].mImages[iImages].mImage.convert(addedSprite->mImages[0].mImage, CL_Rect(0,0,right-left,h), CL_Rect(left, 0, right, h)); } while(residual != 1); */ //удаление исходного разрезаемого изображения sprites.erase( sprites.begin() + iSprites ); } } } // for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) // { // //определение размеров // CL_Size imageSize = iter_sprites->mImage.get_size(); // //Добавление несколько пикселей для границы спрайтов с дублированием граничных пикселей // iter_sprites->image = CL_PixelBufferHelp::add_border(iter_sprites->image, ADDING_BORDER, CL_Rect(0, 0, image_size.width, image_size.height) ); // } /////////////////////////////////////////////////////// //распределение картинок на текстурном атласе /////////////////////////////////////////////////////// for(T_Sprites::size_type iSprites = 0; iSprites < sprites.size(); ++iSprites) { for(S_Sprite::T_Images::size_type iImages = 0; iImages < sprites[iSprites].mImages.size(); ++iImages) { //переполучение размера CL_Size image_size = sprites[iSprites].mImages[iImages].mImage.get_size(); //помещение в отсортированый список указателя на image sortedList.insert( std::make_pair( max(image_size.width, image_size.height), S_ImagePointer(iSprites, iImages) ) ); } } //Проверка сортировки //for(T_SortedList::iterator iter_sortedList = sortedList.begin(); iter_sortedList != sortedList.end(); ++iter_sortedList) // CL_Console::write_line("sorted: %1, key=(%2, %3)", iter_sortedList->first, iter_sortedList->second.iSprite, iter_sortedList->second.iImage); //проход по всем спрайтам по убыванию большей стороны for(T_SortedList::reverse_iterator iter_sortedList = sortedList.rbegin(); iter_sortedList != sortedList.rend(); ++iter_sortedList) { //номер спрайта T_Sprites::size_type iSprite = iter_sortedList->second.iSprite; //номер изображения в спрайте S_Sprite::T_Images::size_type iImage = iter_sortedList->second.iImage; if( !sprites[iSprite].mImages[iImage].mNoTransparent ) pngNodes.ConnectTexture( S_ImagePointer(iSprite, iImage) ); else jpgNodes.ConnectTexture( S_ImagePointer(iSprite, iImage) ); //проверка добавления CL_Console::write_line("rects are %1 %2 %3 %4", sprites[iSprite].mImages[iImage].mSrcRect.left, sprites[iSprite].mImages[iImage].mSrcRect.top, sprites[iSprite].mImages[iImage].mSrcRect.right, sprites[iSprite].mImages[iImage].mSrcRect.bottom); } size_t textureW = MAX_WIDTH; size_t textureH = MAX_HEIGHT; //список текстур PNG std::vector<CL_PixelBuffer> endTexturesPNG; //список текстур JPG std::vector<CL_PixelBuffer> endTexturesJPG; //физическое создание конечных текстур size_t nTexture = pngNodes.GetNumberTextures(); for(size_t iTexture = 0; iTexture < nTexture; ++iTexture) endTexturesPNG.push_back( CL_PixelBuffer(textureW, textureH, cl_rgba8) ); nTexture = jpgNodes.GetNumberTextures(); for(size_t iTexture = 0; iTexture < nTexture; ++iTexture) endTexturesJPG.push_back( CL_PixelBuffer(textureW, textureH, cl_rgb8) ); //обнуление цвета и альфы конечных текстур PNG for(std::vector<CL_PixelBuffer>::iterator iterEndTexture = endTexturesPNG.begin(); iterEndTexture != endTexturesPNG.end(); ++iterEndTexture) memset( (void *)iterEndTexture->get_data(), 0, iterEndTexture->get_pitch()*iterEndTexture->get_height() ); //обнуление цвета конечных текстуры JPG for(std::vector<CL_PixelBuffer>::iterator iterEndTexture = endTexturesJPG.begin(); iterEndTexture != endTexturesJPG.end(); ++iterEndTexture) memset( (void *)iterEndTexture->get_data(), 0, iterEndTexture->get_pitch()*iterEndTexture->get_height() ); //копирование подтекстур в конечные текстуры for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { //размеры добавляемого прямоугольника CL_Rect srcRect = CL_Rect(0, 0, iter_images->mImage.get_width(), iter_images->mImage.get_height()); //номер текстуры size_t iTexture = iter_images->mITexture; if( !iter_images->mNoTransparent ) iter_images->mImage.convert(endTexturesPNG[iTexture], iter_images->mSrcRect, srcRect); else iter_images->mImage.convert(endTexturesJPG[iTexture], iter_images->mSrcRect, srcRect); } } //сохранение текстур PNG std::vector<CL_PixelBuffer>::size_type iEndTexture, nEndTexture; nEndTexture = endTexturesPNG.size(); for(iEndTexture = 0; iEndTexture < nEndTexture; ++iEndTexture) { //Предумножение на альфу endTexturesPNG[iEndTexture].premultiply_alpha(); //сохранение CL_PNGProvider::save(endTexturesPNG[iEndTexture], CL_PathHelp::make_absolute(workDirectoryName, OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iEndTexture) + ".png") ); CL_Console::write_line("saved %1", CL_PathHelp::make_absolute(workDirectoryName, OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iEndTexture) + ".png")); } //сохранение текстур JPG nEndTexture = endTexturesJPG.size(); for(iEndTexture = 0; iEndTexture < nEndTexture; ++iEndTexture) { //сохранение CL_JPEGProvider::save(endTexturesJPG[iEndTexture], CL_PathHelp::make_absolute(workDirectoryName, OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iEndTexture) + ".jpg")); CL_Console::write_line("saved %1", CL_PathHelp::make_absolute(workDirectoryName, OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iEndTexture) + ".jpg")); } //CL_Console::wait_for_key(); #if SAVE_COLLISION != 0 //Запись файлов - контуров//////////////////////////////////////////////////////// //удаление старых файлов for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { CL_String currentOutlineFileName = iter_images->mCollision.GetCollisionFileName(); if ( CL_FileHelp::file_exists(currentOutlineFileName) ) CL_FileHelp::delete_file(currentOutlineFileName); } } //объекты файлов для записи в них данных контуров std::map<CL_String, CL_File> outlineFiles; //открытие файлов for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { CL_String currentOutlineFileName = iter_images->mCollision.GetCollisionFileName(); std::map<CL_String, CL_File>::iterator iterOutlineFiles = outlineFiles.find(currentOutlineFileName); if (iterOutlineFiles == outlineFiles.end()) { CL_File outlineFile; //формирование полного имени файла CL_String currentOutlineFullName = CL_PathHelp::make_absolute(workDirectoryName, currentOutlineFileName); //открытие файла CL_Console::write_line("open outline file: %1", currentOutlineFullName); bool is_opened = outlineFile.open(currentOutlineFullName, CL_File::open_always, CL_File::access_write); if (!is_opened) return PrintError( CL_String("I Can't open file: ") + currentOutlineFullName ); //добавление файла в список открытых файлов outlineFiles.insert( std::make_pair(currentOutlineFileName, outlineFile) ); CL_Console::write_line("-inserted %1", currentOutlineFileName); } } } //сохранение в бинарные файлы данных о контуре for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { CL_String currentOutlineFileName = iter_images->mCollision.GetCollisionFileName(); //сохранение информации о коллизии saveCollision(iter_images->mImage, outlineFiles[currentOutlineFileName]); //установка смещения для последующих таких имён for(T_Sprites::iterator iter_sprites2 = iter_sprites; iter_sprites2 != sprites.end(); ++iter_sprites2) { S_Sprite::T_Images::iterator iter_images2; if(iter_sprites2 == iter_sprites) iter_images2 = iter_images + 1; else iter_images2 = iter_sprites2->mImages.begin(); for(; iter_images2 != iter_sprites2->mImages.end(); ++iter_images2) if(iter_images->mCollision.GetCollisionFileName() == iter_images2->mCollision.GetCollisionFileName()) //CL_Console::write_line("+size %1", outlineFiles[currentOutlineFileName].get_position() ); iter_images2->mCollision.mFileOffset = outlineFiles[currentOutlineFileName].get_position(); } CL_Console::write_line("saved %1: %2 %3", iter_images->mSourceFileName, currentOutlineFileName, iter_images->mCollision.mFileOffset); } } //закрытие файлов for(std::map<CL_String, CL_File>::iterator iterOutlineFiles = outlineFiles.begin(); iterOutlineFiles != outlineFiles.end(); ++iterOutlineFiles) iterOutlineFiles->second.close(); #endif //CL_Console::wait_for_key(); ////////////////////////////////////////////////////////// //формирование имени файла //CL_String fileResourceName = CL_PathHelp::make_absolute(workDirectoryName, locationName + ".xml"); CL_String fileResourceName = CL_PathHelp::make_absolute(workDirectoryName, RESOURCES_FILE_NAME); CL_Console::write_line("fileResourceName: %1", fileResourceName); //открытие файла XML CL_File fileResourceXML; bool is_opened = fileResourceXML.open(fileResourceName, CL_File::create_always, CL_File::access_write); if( !is_opened ) return PrintError( CL_String("I Can't open file: ") + fileResourceName ); //запись файл заголовка fileResourceXML.write_string_text("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //Создание объекта DOM парсера CL_DomDocument resourceXML; //корневой узел - resources CL_DomElement resourcesElement(resourceXML, "resources"); resourceXML.append_child(resourcesElement); //узлы bitmap std::map<CL_String, CL_String> complianceCollisions; //формирование map-ы bitmap for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) complianceCollisions.insert( std::make_pair(iter_images->mCollision.GetCollisionFileName(), iter_images->mCollision.GetCollisionName()) ); #if SAVE_COLLISION != 0 //запись в XML файл ресурсов битовых масок for(std::map<CL_String, CL_String>::iterator iterComplianceCollisions = complianceCollisions.begin(); iterComplianceCollisions != complianceCollisions.end(); ++iterComplianceCollisions) { CL_DomElement bitmapElement(resourceXML, "bitmap"); bitmapElement.set_attribute("name", iterComplianceCollisions->second); bitmapElement.set_attribute("file", iterComplianceCollisions->first); resourcesElement.append_child(bitmapElement); } #endif //запись в XML файл ресурсов результирующих прямоугольников for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { CL_String currentResourceName = iter_sprites->mName; //узел - sprite CL_DomElement spriteElement(resourceXML, "sprite"); spriteElement.set_attribute("name", currentResourceName); resourcesElement.append_child(spriteElement); //тэг image for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { CL_Rect currentSrcRect = iter_images->mSrcRect; //узел - image CL_DomElement imageElement(resourceXML, "image"); if( !iter_images->mNoTransparent ) imageElement.set_attribute("file", OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iter_images->mITexture) + ".png"); else imageElement.set_attribute("file", OUTPUT_TEXTURE_NAME + CL_StringHelp::int_to_text(iter_images->mITexture) + ".jpg"); spriteElement.append_child(imageElement); #if SAVE_COLLISION != 0 //сохранение коллизий imageElement.set_attribute("bitmap", iter_images->mCollision.GetCollisionName()); imageElement.set_attribute_int("offset", iter_images->mCollision.mFileOffset); #endif //элемент grid CL_DomElement GridElement(resourceXML, "grid"); GridElement.set_attribute("pos", cl_format("%1,%2", currentSrcRect.left + iter_images->mDeltaGrid.left, currentSrcRect.top + iter_images->mDeltaGrid.top) ); GridElement.set_attribute("size", cl_format("%1,%2", currentSrcRect.right-currentSrcRect.left + iter_images->mDeltaGrid.right, currentSrcRect.bottom-currentSrcRect.top + iter_images->mDeltaGrid.bottom) ); imageElement.append_child(GridElement); } //прервать выполнение сохранения, если анимации нет if (!iter_sprites->mIsFrame) continue; for(S_Sprite::T_Images::iterator iter_images = iter_sprites->mImages.begin(); iter_images != iter_sprites->mImages.end(); ++iter_images) { //элемент frame CL_DomElement frameElement(resourceXML, "frame"); frameElement.set_attribute_int("nr", iter_images - iter_sprites->mImages.begin()); if (iter_images->mDelay != 0) frameElement.set_attribute_int("speed", iter_images->mDelay); frameElement.set_attribute_int("x", iter_images->mOffset.x); frameElement.set_attribute_int("y", iter_images->mOffset.y); spriteElement.append_child(frameElement); } } //подключение всех файлов с дополнительными ресурсами directoryScanner.scan(workDirectoryName, "*.xml"); while (directoryScanner.next()) { //проверка валидности файла if (directoryScanner.is_directory() || directoryScanner.get_name() == RESOURCES_FILE_NAME) continue; //открытие ресурсного XML файла CL_Console::write_line("include xml file: " + directoryScanner.get_pathname()); CL_File file(directoryScanner.get_pathname()); CL_DomDocument doc(file); CL_DomElement root = doc.get_document_element(); if (root.get_tag_name() != "resources") { CL_Console::write_line("Root name can't be: %1", root.get_tag_name()); return PrintError(""); } //добавление всех ресурсов в текущий документ for (CL_DomElement element = root.get_first_child_element(); !element.is_null(); element = element.get_next_sibling_element()) resourcesElement.append_child(cloneElement(element, resourceXML)); } //сохранение в файл XML структуры resourceXML.save(fileResourceXML); //закрытие файла fileResourceXML.close(); //сохранение координат спрайтов и инициализации/деинициализации в lua скрипте //формирование имени файла //CL_String luaFileName = CL_PathHelp::make_absolute(workDirectoryName, locationName + ".lua"); CL_String luaFileName = CL_PathHelp::make_absolute(workDirectoryName, LUA_SCRIPT_NAME); CL_File luaFile; is_opened = luaFile.open(luaFileName, CL_File::create_always, CL_File::access_write); if( !is_opened ) return PrintError( CL_String("Can't open file: ") + luaFileName); luaFile.write_string_text( cl_format("function %1_createSprites()", locationName) ); //запись в XML файл ресурсов результирующих прямоугольников for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { CL_String currentResourceName = iter_sprites->mName; int x = iter_sprites->mPos.x; int y = iter_sprites->mPos.y; luaFile.write_string_text( cl_format("\t%1 = Sprite(\"%2\", %3, %4)", currentResourceName, currentResourceName, x, y) ); } luaFile.write_string_text( cl_format("end") ); luaFile.write_string_text(CL_String("")); luaFile.write_string_text( cl_format("function %1_deleteSprites()", locationName) ); //запись в XML файл ресурсов результирующих прямоугольников for(T_Sprites::iterator iter_sprites = sprites.begin(); iter_sprites != sprites.end(); ++iter_sprites) { CL_String currentResourceName = iter_sprites->mName; luaFile.write_string_text( cl_format("\t%1 = nil", currentResourceName) ); } luaFile.write_string_text( cl_format("end") ); /* function Location01_createSprites() sprite1 = Sprite("sprite1", 10, 20) sprite2 = Sprite("sprite2", 13, 666) ... spriten = Sprite("spriten", 999, 0) end function Location01_deleteSprites() sprite1 = nil sprite2 = nil ... spriten = nil end */ luaFile.close(); CL_Console::write_line("Press any key..."); CL_Console::wait_for_key(); } catch(CL_Exception &exception) { CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); CL_Console::wait_for_key(); return -1; } return 0; }
int main( int argc, char** argv ) { QApplication app( argc, argv ); KDReports::Report report; report.setHeaderBodySpacing( 10 ); // mm report.setFooterBodySpacing( 10 ); // mm // report.setWatermarkPixmap( QPixmap( ":/kdab.jpg" ) ); // report.setWatermarkText( QString::null ); KDReports::Header& header = report.header( KDReports::OddPages ); QPixmap kdab( ":/kdab_small.jpg" ); // add a border around the pixmap, mostly for debugging //QPainter painter( &kdab ); //painter.drawRect( 0, 0, kdab.width() - 1, kdab.height() - 1 ); KDReports::ImageElement imageElement( kdab ); // The image size can be set in mm or in percent of the page width (without margins) // imageElement.setWidth( 50 ); // mm imageElement.setWidth( 40, KDReports::Percent ); header.addElement( imageElement ); header.addVariable( KDReports::PageNumber ); header.addInlineElement( KDReports::TextElement( " / " ) ); header.addVariable( KDReports::PageCount ); header.addInlineElement( KDReports::TextElement( ", Date: " ) ); header.addVariable( KDReports::TextDate ); header.addInlineElement( KDReports::TextElement( ", Time: " ) ); header.addVariable( KDReports::TextTime ); KDReports::Header& evenPagesHeader = report.header( KDReports::EvenPages ); evenPagesHeader.addElement( imageElement ); evenPagesHeader.addInlineElement( KDReports::TextElement( "Even pages header: " ) ); evenPagesHeader.addVariable( KDReports::PageNumber ); evenPagesHeader.addInlineElement( KDReports::TextElement( " / " ) ); evenPagesHeader.addVariable( KDReports::PageCount ); KDReports::Footer& footer = report.footer(); KDReports::TextElement companyAddressElement( QString::fromUtf8( "Klarälvdalens Datakonsult AB\nRysktorp\nSE-68392 Hagfors\nSweden" ) ); footer.addElement( companyAddressElement, Qt::AlignRight ); KDReports::TextElement titleElement; titleElement << "Price list example"; titleElement.setPointSize( 18 ); report.addElement( titleElement, Qt::AlignHCenter ); report.addVerticalSpacing( 10 ); // 1 cm const QColor titleElementColor( 204, 204, 255 ); // A text element with the title above a table // Note that the background color is not just behind the text (as setBackground() would do), // but behind the whole paragraph, up until the right margin of the page. KDReports::TextElement tableTitleElement( "Network Peripherals" ); tableTitleElement.setBold( true ); report.addElement( tableTitleElement, Qt::AlignLeft, titleElementColor ); TableModel table1; table1.setDataHasVerticalHeaders( false ); table1.loadFromCSV( ":/table1" ); // Q_ASSERT( table1.headerData( 0, Qt::Vertical ).toString() == "10/100 Mbps switch" ); //Q_ASSERT( table1.data( table1.index( 0, 0 ) ).toString() == "Product" ); KDReports::AutoTableElement autoTableElement1( &table1 ); autoTableElement1.setWidth( 100, KDReports::Percent ); report.addElement( autoTableElement1 ); report.addVerticalSpacing( 5 ); // Notice how elements can be copied and modified // This way, we use the same font attributes for all title elements KDReports::TextElement tableTitleElement2 = tableTitleElement; tableTitleElement2.setText( "Printer Cartridges" ); report.addElement( tableTitleElement2, Qt::AlignLeft, titleElementColor ); TableModel table2; table2.setDataHasVerticalHeaders( false ); table2.loadFromCSV( ":/table2" ); KDReports::AutoTableElement autoTableElement2( &table2 ); autoTableElement2.setWidth( 100, KDReports::Percent ); report.addElement( autoTableElement2 ); // and again, on the second page report.addPageBreak(); report.addElement( tableTitleElement, Qt::AlignLeft, titleElementColor ); report.addElement( autoTableElement1 ); report.addVerticalSpacing( 5 ); report.addElement( tableTitleElement2, Qt::AlignLeft, titleElementColor ); report.addElement( autoTableElement2 ); report.addVerticalSpacing( 5 ); // =========================================================================== // Another kind of table, where the data comes from code and not from a model: // =========================================================================== KDReports::TableElement tableElement; tableElement.setHeaderRowCount( 2 ); tableElement.setPadding( 3 ); QColor headerColor( "#DADADA" ); // Merged header in row 0 KDReports::Cell& topHeader = tableElement.cell( 0, 0 ); topHeader.setColumnSpan( 2 ); topHeader.setBackground( headerColor ); topHeader.addElement( KDReports::TextElement( "TableElement example" ), Qt::AlignHCenter ); // Normal header in row 1 KDReports::Cell& headerCell1 = tableElement.cell( 1, 0 ); headerCell1.setBackground( headerColor ); // This would look better if centered vertically. This feature is only available since // Qt-4.3 though (QTextCharFormat::AlignMiddle) QPixmap systemPixmap( ":/system.png" ); headerCell1.addElement( KDReports::ImageElement( systemPixmap ) ); headerCell1.addInlineElement( KDReports::TextElement( " Item" ) ); KDReports::Cell& headerCell2 = tableElement.cell( 1, 1 ); headerCell2.setBackground( headerColor ); KDReports::TextElement expected( "Expected" ); expected.setItalic( true ); expected.setBackground( QColor("#999999") ); // note that this background only applies to this element headerCell2.addElement( expected ); headerCell2.addInlineElement( KDReports::TextElement( " shipping time" ) ); // Data in rows 2 and 3 tableElement.cell( 2, 0 ).addElement( KDReports::TextElement( "Network Peripherals" ) ); tableElement.cell( 2, 1 ).addElement( KDReports::TextElement( "4 days" ) ); tableElement.cell( 3, 0 ).addElement( KDReports::TextElement( "Printer Cartridges" ) ); tableElement.cell( 3, 1 ).addElement( KDReports::TextElement( "3 days" ) ); report.addElement( tableElement ); KDReports::PreviewDialog preview( &report ); return preview.exec(); }