void ImageExportOptionsWidget::updateFromPixelSize(const QSize &pixelSize) { blockChildSignals(true); double inchWidth = static_cast<double>(pixelSize.width()) / static_cast<double>(widget.dpi->value()); double inchHeight = static_cast<double>(pixelSize.height()) / static_cast<double>(widget.dpi->value()); widget.unitWidth->changeValue(INCH_TO_POINT(inchWidth)); widget.unitHeight->changeValue(INCH_TO_POINT(inchHeight)); blockChildSignals(false); }
qreal FopInt( const QString datain ) { QString ctmp = datain; const QString data = ctmp.replace(" ","").trimmed(); //////////qDebug() << "### request unit data->" << datain << " size->" << datain.size(); qreal points = 0; if (data.size() < 1) { return points; } if ( data.endsWith( "%" )) { return 12.5; } if (datain == "0") { return points; } if ( data.endsWith( "pt" ) || data.endsWith( "px" ) ) { points = data.left( data.length() - 2 ).toDouble(); return points; } else if ( data.endsWith( "cm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = CM_TO_POINT( value ); } else if ( data.endsWith( "em" ) ) { points = data.left( data.length() - 2 ).toDouble(); } else if ( data.endsWith( "mm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = MM_TO_POINT( value ); } else if ( data.endsWith( "dm" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = DM_TO_POINT( value ); } else if ( data.endsWith( "in" ) ) { double value = data.left( data.length() - 2 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "inch" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = INCH_TO_POINT( value ); } else if ( data.endsWith( "pi" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = PI_TO_POINT( value ); } else if ( data.endsWith( "dd" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = DD_TO_POINT( value ); } else if ( data.endsWith( "cc" ) ) { double value = data.left( data.length() - 4 ).toDouble(); points = CC_TO_POINT( value ); } else { points = 0; } return points; }
void KReportPosition::setScenePos(const QPointF& pos, UpdatePropertyFlag update) { QScreen *srn = QApplication::screens().at(0); const qreal x = INCH_TO_POINT(pos.x() / srn->logicalDotsPerInchX()); const qreal y = INCH_TO_POINT(pos.y() / srn->logicalDotsPerInchY()); m_pointPos.setX(x); m_pointPos.setY(y); if (update == UpdateProperty) m_property->setValue(toUnit()); }
void zoomhandler_test::testConstruction() { KoZoomHandler * zoomHandler = new KoZoomHandler(); QCOMPARE( zoomHandler->zoomFactorX(), 1. ); QCOMPARE( zoomHandler->zoomFactorY(), 1. ); QCOMPARE( ( int )INCH_TO_POINT( zoomHandler->resolutionX() ), ( int )KoDpi::dpiX() ); QCOMPARE( ( int )INCH_TO_POINT( zoomHandler->resolutionY() ), ( int )KoDpi::dpiY() ); QCOMPARE( ( int )INCH_TO_POINT( zoomHandler->zoomedResolutionX() ), ( int )KoDpi::dpiX() ); QCOMPARE( ( int )INCH_TO_POINT( zoomHandler->zoomedResolutionY() ), ( int )KoDpi::dpiY() ); QCOMPARE( zoomHandler->zoomMode(), KoZoomMode::ZOOM_CONSTANT ); QCOMPARE( zoomHandler->zoomInPercent(), 100 ); delete zoomHandler; }
qreal ToPoint( qreal unit , const QString unita ) { qreal ri = 0; if (unita == "cm") { ri = CM_TO_POINT( unit ); } else if (unita == "pt" || unita == "px" ) { ri = unit; return ri; } else if (unita == "mm") { ri = MM_TO_POINT( unit ); } else if (unita == "dm") { ri = DM_TO_POINT( unit ); } else if (unita == "inch") { ri = INCH_TO_POINT( unit ); } else if (unita == "pi") { ri = PI_TO_POINT( unit ); } else if (unita == "dd") { ri = DD_TO_POINT( unit ); } else if (unita == "cc") { ri = CC_TO_POINT( unit ); } else { ri = 10; } return ri; }
qreal KoUnit::convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor) { qreal pt; switch (fromUnit.type()) { case Millimeter: pt = MM_TO_POINT(value); break; case Centimeter: pt = CM_TO_POINT(value); break; case Decimeter: pt = DM_TO_POINT(value); break; case Inch: pt = INCH_TO_POINT(value); break; case Pica: pt = PI_TO_POINT(value); break; case Cicero: pt = CC_TO_POINT(value); break; case Pixel: pt = value / factor; break; case Point: default: pt = value; } switch (toUnit.type()) { case Millimeter: return POINT_TO_MM(pt); case Centimeter: return POINT_TO_CM(pt); case Decimeter: return POINT_TO_DM(pt); case Inch: return POINT_TO_INCH(pt); case Pica: return POINT_TO_PI(pt); case Cicero: return POINT_TO_CC(pt); case Pixel: return pt * factor; case Point: default: return pt; } }
void ReportSection::buildXML(QDomDocument & doc, QDomElement & section) { int dpiY = KoGlobal::dpiY(); qreal f = INCH_TO_POINT(m_scene->height() / dpiY); //f = ( ( f - ( int ) f ) > .5 ? f : f + 1 ); QDomElement height = doc.createElement("height"); height.appendChild(doc.createTextNode(QString::number(f))); section.appendChild(height); QDomElement bgcolor = doc.createElement("bgcolor"); bgcolor.appendChild(doc.createTextNode(m_sectionData->bgColor().name())); section.appendChild(bgcolor); // now get a list of all the QCanvasItems on this scene and output them. QGraphicsItemList list = m_scene->items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); it++) { ReportEntity::buildXML((*it), doc, section); } }
qreal KoUnit::fromUserValue(qreal value) const { switch (m_type) { case Millimeter: return MM_TO_POINT(value); case Centimeter: return CM_TO_POINT(value); case Decimeter: return DM_TO_POINT(value); case Inch: return INCH_TO_POINT(value); case Pica: return PI_TO_POINT(value); case Cicero: return CC_TO_POINT(value); case Pixel: return value / m_pixelConversion; case Point: default: return value; } }
KisImageBuilder_Result PSDSaver::buildFile(QIODevice *io) { if (!m_image) return KisImageBuilder_RESULT_EMPTY; const bool haveLayers = m_image->rootLayer()->childCount() > 1 || checkIfHasTransparency(m_image->rootLayer()->firstChild()->projection()); // HEADER PSDHeader header; header.signature = "8BPS"; header.version = 1; header.nChannels = haveLayers ? m_image->colorSpace()->channelCount() : m_image->colorSpace()->colorChannelCount(); header.width = m_image->width(); header.height = m_image->height(); QPair<psd_color_mode, quint16> colordef = colormodelid_to_psd_colormode(m_image->colorSpace()->colorModelId().id(), m_image->colorSpace()->colorDepthId().id()); if (colordef.first == COLORMODE_UNKNOWN || colordef.second == 0 || colordef.second == 32) { return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } header.colormode = colordef.first; header.channelDepth = colordef.second; dbgFile << "header" << header << io->pos(); if (!header.write(io)) { dbgFile << "Failed to write header. Error:" << header.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // COLORMODE BlOCK PSDColorModeBlock colorModeBlock(header.colormode); // XXX: check for annotations that contain the duotone spec KisAnnotationSP annotation = m_image->annotation("DuotoneColormodeBlock"); if (annotation) { colorModeBlock.duotoneSpecification = annotation->annotation(); } dbgFile << "colormode block" << io->pos(); if (!colorModeBlock.write(io)) { dbgFile << "Failed to write colormode block. Error:" << colorModeBlock.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // IMAGE RESOURCES SECTION PSDImageResourceSection resourceSection; vKisAnnotationSP_it it = m_image->beginAnnotations(); vKisAnnotationSP_it endIt = m_image->endAnnotations(); while (it != endIt) { KisAnnotationSP annotation = (*it); if (!annotation || annotation->type().isEmpty()) { dbgFile << "Warning: empty annotation"; it++; continue; } dbgFile << "Annotation:" << annotation->type() << annotation->description(); if (annotation->type().startsWith(QString("PSD Resource Block:"))) { // PSDResourceBlock *resourceBlock = dynamic_cast<PSDResourceBlock*>(annotation.data()); if (resourceBlock) { dbgFile << "Adding PSD Resource Block" << resourceBlock->identifier; resourceSection.resources[(PSDImageResourceSection::PSDResourceID)resourceBlock->identifier] = resourceBlock; } } it++; } // Add resolution block { RESN_INFO_1005 *resInfo = new RESN_INFO_1005; resInfo->hRes = INCH_TO_POINT(m_image->xRes()); resInfo->vRes = INCH_TO_POINT(m_image->yRes()); PSDResourceBlock *block = new PSDResourceBlock; block->identifier = PSDImageResourceSection::RESN_INFO; block->resource = resInfo; resourceSection.resources[PSDImageResourceSection::RESN_INFO] = block; } // Add icc block { ICC_PROFILE_1039 *profileInfo = new ICC_PROFILE_1039; profileInfo->icc = m_image->profile()->rawData(); PSDResourceBlock *block = new PSDResourceBlock; block->identifier = PSDImageResourceSection::ICC_PROFILE; block->resource = profileInfo; resourceSection.resources[PSDImageResourceSection::ICC_PROFILE] = block; } dbgFile << "resource section" << io->pos(); if (!resourceSection.write(io)) { dbgFile << "Failed to write resource section. Error:" << resourceSection.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } // LAYER AND MASK DATA // Only save layers and masks if there is more than one layer dbgFile << "m_image->rootLayer->childCount" << m_image->rootLayer()->childCount() << io->pos(); if (haveLayers) { PSDLayerMaskSection layerSection(header); layerSection.hasTransparency = true; if (!layerSection.write(io, m_image->rootLayer())) { dbgFile << "failed to write layer section. Error:" << layerSection.error << io->pos(); return KisImageBuilder_RESULT_FAILURE; } } else { // else write a zero length block dbgFile << "No layers, saving empty layers/mask block" << io->pos(); psdwrite(io, (quint32)0); } // IMAGE DATA dbgFile << "Saving composited image" << io->pos(); PSDImageData imagedata(&header); if (!imagedata.write(io, m_image->projection(), haveLayers)) { dbgFile << "Failed to write image data. Error:" << imagedata.error; return KisImageBuilder_RESULT_FAILURE; } return KisImageBuilder_RESULT_OK; }
KisImageBuilder_Result PSDSaver::buildFile(const KUrl& uri) { if (!m_image) return KisImageBuilder_RESULT_EMPTY; if (uri.isEmpty()) return KisImageBuilder_RESULT_NO_URI; if (!uri.isLocalFile()) return KisImageBuilder_RESULT_NOT_LOCAL; // Open file for writing QFile f(uri.toLocalFile()); if (!f.open(QIODevice::WriteOnly)) { return KisImageBuilder_RESULT_NOT_LOCAL; } // HEADER PSDHeader header; header.signature = "8BPS"; header.version = 1; header.nChannels = m_image->colorSpace()->channelCount(); header.width = m_image->width(); header.height = m_image->height(); QPair<PSDColorMode, quint16> colordef = colormodelid_to_psd_colormode(m_image->colorSpace()->colorModelId().id(), m_image->colorSpace()->colorDepthId().id()); if (colordef.first == UNKNOWN || colordef.second == 0 || colordef.second == 32) { return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } header.colormode = colordef.first; header.channelDepth = colordef.second; dbgFile << "header" << header << f.pos(); if (!header.write(&f)) { dbgFile << "Failed to write header. Error:" << header.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // COLORMODE BlOCK PSDColorModeBlock colorModeBlock(header.colormode); // XXX: check for annotations that contain the duotone spec dbgFile << "colormode block" << f.pos(); if (!colorModeBlock.write(&f)) { dbgFile << "Failed to write colormode block. Error:" << colorModeBlock.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // IMAGE RESOURCES SECTION PSDResourceSection resourceSection; // Add resolution block { RESN_INFO_1005 *resInfo = new RESN_INFO_1005; resInfo->hRes = INCH_TO_POINT(m_image->xRes()); resInfo->vRes = INCH_TO_POINT(m_image->yRes()); PSDResourceBlock *block = new PSDResourceBlock; block->resource = resInfo; resourceSection.resources[PSDResourceSection::RESN_INFO] = block; } // Add icc block { ICC_PROFILE_1039 *profileInfo = new ICC_PROFILE_1039; profileInfo->icc = m_image->profile()->rawData(); PSDResourceBlock *block = new PSDResourceBlock; block->resource = profileInfo; resourceSection.resources[PSDResourceSection::ICC_PROFILE] = block; } // XXX: Add other blocks... dbgFile << "resource section" << f.pos(); if (!resourceSection.write(&f)) { dbgFile << "Failed to write resource section. Error:" << resourceSection.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } // LAYER AND MASK DATA // Only save layers and masks if there is more than one layer dbgFile << "m_image->rootLayer->childCount" << m_image->rootLayer()->childCount() << f.pos(); if (m_image->rootLayer()->childCount() > 1) { PSDLayerSection layerSection(header); layerSection.hasTransparency = true; if (!layerSection.write(&f, m_image->rootLayer())) { dbgFile << "failed to write layer section. Error:" << layerSection.error << f.pos(); return KisImageBuilder_RESULT_FAILURE; } } else { // else write a zero length block dbgFile << "No layers, saving empty layers/mask block" << f.pos(); psdwrite(&f, (quint32)0); } // IMAGE DATA dbgFile << "Saving composited image" << f.pos(); PSDImageData imagedata(&header); if (!imagedata.write(&f, m_image->projection())) { dbgFile << "Failed to write image data. Error:" << imagedata.error; return KisImageBuilder_RESULT_FAILURE; } f.close(); return KisImageBuilder_RESULT_OK; }