void DocumentTest::testReadWriteFormula() { QBuffer device; device.open(QIODevice::WriteOnly); Document xlsx1; xlsx1.write("A1", "=11+22"); Format format; format.setFontColor(Qt::blue); format.setBorderStyle(Format::BorderDashDotDot); format.setFillPattern(Format::PatternSolid); xlsx1.write("A2", "=22+33", format); xlsx1.saveAs(&device); device.open(QIODevice::ReadOnly); Document xlsx2(&device); QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::Formula); // QCOMPARE(xlsx2.cellAt("A1")->value().toDouble(), 0.0); QCOMPARE(xlsx2.cellAt("A1")->formula(), QStringLiteral("11+22")); QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Formula); // QCOMPARE(xlsx2.cellAt("A2")->value().toDouble(), 0.0); QCOMPARE(xlsx2.cellAt("A2")->formula(), QStringLiteral("22+33")); QVERIFY(xlsx2.cellAt("A2")->format().isValid()); QCOMPARE(xlsx2.cellAt("A2")->format(), format); }
void Xlsxcontrol::writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern, const QColor &color) { Format format; format.setPatternForegroundColor(color); format.setFillPattern(pattern); xlsx.write(cell, QVariant(), format); }
void Xlsxcontrol::writeFontNameCell(Document &xlsx, const QString &cell, const QString &text) { Format format; format.setFontName(text); format.setFontSize(16); xlsx.write(cell, text, format); }
IECore::MurmurHash FormatPlug::hash() const { IECore::MurmurHash result; if( direction()==Plug::In && !getInput<ValuePlug>() ) { Format v = getValue(); if( v.getDisplayWindow().isEmpty() ) { const Gaffer::Node *n( node() ); if( n ) { const Gaffer::ScriptNode *s( n->scriptNode() ); if ( s ) { const GafferImage::FormatPlug *p( s->getChild<FormatPlug>( GafferImage::Format::defaultFormatPlugName ) ); if ( p ) { v = p->getValue(); } } } } result.append( v.getDisplayWindow().min ); result.append( v.getDisplayWindow().max ); result.append( v.getPixelAspect() ); } else { result = ValuePlug::hash(); } return result; } // namespace Gaffer
FormatPlug::FormatPlug( const std::string &name, Direction direction, Format defaultValue, unsigned flags ) : ValuePlug( name, direction, flags ), m_defaultValue( defaultValue ) { const unsigned childFlags = flags & ~Dynamic; addChild( new Box2iPlug( "displayWindow", direction, defaultValue.getDisplayWindow(), childFlags ) ); addChild( new FloatPlug( "pixelAspect", direction, defaultValue.getPixelAspect(), Imath::limits<float>::min(), Imath::limits<float>::max(), childFlags ) ); }
// Leanify the file // and move the file ahead size_leanified bytes // the new location of the file will be file_pointer - size_leanified // it's designed this way to avoid extra memmove or memcpy // return new size size_t LeanifyFile(void* file_pointer, size_t file_size, size_t size_leanified /*= 0*/, const string& filename /*= ""*/) { Format* f = GetType(file_pointer, file_size, filename); size_t r = f->Leanify(size_leanified); delete f; return r; }
int main() { Book* book = xlCreateBook(); if(book) { Font* font = book->addFont(); font->setName(L"Impact"); font->setSize(36); Format* format = book->addFormat(); format->setAlignH(ALIGNH_CENTER); format->setBorder(BORDERSTYLE_MEDIUMDASHDOTDOT); format->setBorderColor(COLOR_RED); format->setFont(font); Sheet* sheet = book->addSheet(L"Custom"); if(sheet) { sheet->writeStr(2, 1, L"Format", format); sheet->setCol(1, 1, 25); } if(book->save(L"format.xls")) { ::ShellExecute(NULL, L"open", L"format.xls", NULL, NULL, SW_SHOW); } } return 0; }
void PCMCoder::encode(const Buffer &buffer, std::ofstream &out) const { RIFFHeaderChunk header_chunk; try { Format fmt = buffer.format(); memcpy(header_chunk.id, "RIFF", 4); memcpy(header_chunk.format, "WAVE", 4); header_chunk.size = 4 + sizeof(WaveFormatChunk) + sizeof(WaveDataChunk) + fmt.sizeForFrameCount(buffer.frameCount()); debug_riff_header_chunk(header_chunk); out.write((const char *)&header_chunk, sizeof(RIFFHeaderChunk)); WaveFormatChunk wave_format; memcpy(wave_format.id, "fmt ", 4); wave_format.size = sizeof(WaveFormatChunk) - sizeof(wave_format.id) - sizeof(wave_format.size); wave_format.audioFormat = 1; wave_format.channelCount = fmt.channelCount(); wave_format.sampleRate = fmt.sampleRate(); wave_format.byteRate = fmt.sizeForFrameCount(fmt.sampleRate()); wave_format.bytePerFrame = fmt.sizeForFrameCount(1); wave_format.bitPerSample = fmt.bitDepth(); debug_wave_format_chunk(wave_format); out.write((const char *)&wave_format, sizeof(WaveFormatChunk)); WaveDataChunk wave_data; memcpy(wave_data.id, "data", 4); wave_data.size = fmt.sizeForFrameCount(buffer.frameCount()); debug_wave_data_chunk(wave_data); out.write((const char *)&wave_data, sizeof(WaveDataChunk)); out.write((const char *)buffer.data(), fmt.sizeForFrameCount(buffer.frameCount())); } catch (std::ofstream::failure ioerr) { Error::raise(Error::Status::IOError, ioerr.what()); } }
void Device::updateFormat( const Format &format ) { size_t sampleRate = format.getSampleRate(); size_t framesPerBlock = format.getFramesPerBlock(); if( mSampleRate == sampleRate && mFramesPerBlock == framesPerBlock ) return; auto deviceMgr = Context::deviceManager(); mSignalParamsWillChange.emit(); if( sampleRate && sampleRate != mSampleRate ) { // set the samplerate to 0, forcing it to refresh on next get. mSampleRate = 0; deviceMgr->setSampleRate( shared_from_this(), sampleRate ); } if( framesPerBlock && framesPerBlock != mFramesPerBlock ) { // set the frames per block to 0, forcing it to refresh on next get mFramesPerBlock = 0; deviceMgr->setFramesPerBlock( shared_from_this(), framesPerBlock ); } if( ! deviceMgr->isFormatUpdatedAsync() ) mSignalParamsDidChange.emit(); }
int main() { Book* book = xlCreateBook(); if(book) { Sheet* sheet = book->addSheet("Sheet1"); if(sheet) { sheet->writeStr(2, 1, "Hello, World !"); sheet->writeNum(3, 1, 1000); Format* dateFormat = book->addFormat(); dateFormat->setNumFormat(NUMFORMAT_DATE); sheet->writeNum(4, 1, book->datePack(2008, 4, 29), dateFormat); sheet->setCol(1, 1, 12); } if(book->save("example.xls")) std::cout << "\nFile example.xls has been created." << std::endl; book->release(); } std::cout << "\nPress any key to exit..."; _getch(); return 0; }
bool FontSettings::loadColorScheme(const QString &fileName, const FormatDescriptions &descriptions) { bool loaded = true; m_schemeFileName = fileName; if (!m_scheme.load(m_schemeFileName)) { loaded = false; m_schemeFileName.clear(); qWarning() << "Failed to load color scheme:" << fileName; } // Apply default formats to undefined categories foreach (const FormatDescription &desc, descriptions) { const TextStyle id = desc.id(); if (!m_scheme.contains(id)) { Format format; format.setForeground(desc.foreground()); format.setBackground(desc.background()); format.setBold(desc.format().bold()); format.setItalic(desc.format().italic()); m_scheme.setFormatFor(id, format); } } return loaded; }
void Grammar::get_format_info( SchemeFormatInfo* info, const string& cur_code, INFO type ) const { // TODO: Adjust priority for inherited grammars. for( FormatMap::const_iterator it = m_formats.begin() ; it != m_formats.end() ; it++ ) { Format* fmt = it->second; string str = type == INPUT_INFO ? fmt->get_user_input_str() : fmt->get_user_output_str(); if( str.empty() ) { continue; } PCode pcode; pcode.code = fmt->get_code(); pcode.priority = fmt->get_priority(); bool found = false; for( size_t i = 0 ; i < info->descs.size() ; i++ ) { if( info->descs[i].desc == str ) { // We are already there. found = true; if( pcode.code == cur_code ) { info->current = i; } bool inserted = false; for( size_t j = 0 ; j < info->descs[i].codes.size() ; j++ ) { int p = info->descs[i].codes[j].priority; if( pcode.priority > p ) { // Insert it here. info->descs[i].codes.insert( info->descs[i].codes.begin() + j, pcode ); inserted = true; break; } } if( !inserted ) { info->descs[i].codes.push_back( pcode ); } break; } else { for ( size_t j = 0; j < info->descs[i].codes.size(); j++ ) { if ( pcode.code == info->descs[i].codes[j].code ) { found = true; break; } } if ( found ) { break; } } } if( !found ) { PDesc desc; desc.desc = str; desc.codes.push_back( pcode ); if( pcode.code == cur_code ) { info->current = info->descs.size(); } info->descs.push_back( desc ); } } if( m_inherit ) { m_inherit->get_format_info( info, cur_code, type ); } }
/*# @method format Format @brief Performs desired formatting on a target item. @param item The item to be formatted @optparam dest A string where to store the formatted data. @return A formatted string @raise ParamError if a format specifier has not been set yet. @raise TypeError if the format specifier can't be applied the item because of incompatible type. Formats the variable as per the given format descriptor. If the class has been instantiated without format, and the parse() method has not been called yet, a ParamError is raised. If the type of the variable is incompatible with the format descriptor, the method returns nil; a particular format specifier allows to throw a TypeError in this case. On success, the method returns a string containing a valid formatted representation of the variable. It is possible to provide a pre-allocated string where to store the formatted result to improve performace and spare memory. */ FALCON_FUNC Format_format ( ::Falcon::VMachine *vm ) { CoreObject *einst = vm->self().asObject(); Format *fmt = dyncast<Format*>( einst->getFalconData() ); Item *param = vm->param( 0 ); Item *dest = vm->param( 1 ); if( param == 0 || ( dest != 0 && ! dest->isString() ) ) { throw new ParamError( ErrorParam( e_inv_params ).extra( "X,[S]" ) ); } else { CoreString *tgt; if( dest != 0 ) { tgt = dest->asCoreString(); } else { tgt = new CoreString; } if( ! fmt->format( vm, *param, *tgt ) ) vm->retnil(); else vm->retval( tgt ); } }
void DocumentTest::testReadWriteString() { QBuffer device; device.open(QIODevice::WriteOnly); Document xlsx1; xlsx1.write("A1", "Hello Qt!"); Format format; format.setFontColor(Qt::blue); format.setBorderStyle(Format::BorderDashDotDot); format.setFillPattern(Format::PatternSolid); xlsx1.write("A2", "Hello Qt again!", format); xlsx1.write("A3", "12345"); xlsx1.saveAs(&device); device.open(QIODevice::ReadOnly); Document xlsx2(&device); QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::String); QCOMPARE(xlsx2.cellAt("A1")->value().toString(), QString("Hello Qt!")); QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::String); QCOMPARE(xlsx2.cellAt("A2")->value().toString(), QString("Hello Qt again!")); Format format2 = xlsx2.cellAt("A2")->format(); QVERIFY(format2.isValid()); // qDebug()<<format2; // qDebug()<<format; QCOMPARE(format2, format); QCOMPARE(xlsx2.cellAt("A3")->dataType(), Cell::String); QCOMPARE(xlsx2.cellAt("A3")->value().toString(), QString("12345")); }
void Xlsxcontrol::writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text, Format::HorizontalAlignment align) { Format format; format.setHorizontalAlignment(align); format.setBorderStyle(Format::BorderThin); xlsx.write(cell, text, format); }
void SimpleDataHolder<Format>::hash( MurmurHash &h ) const { Format f = readable(); h.append( f.getDisplayWindow().min ); h.append( f.getDisplayWindow().max ); h.append( f.getPixelAspect() ); }
void DocumentTest::testReadWriteBlank() { QBuffer device; device.open(QIODevice::WriteOnly); Document xlsx1; xlsx1.write("A1", QVariant()); Format format; format.setFontColor(Qt::blue); format.setBorderStyle(Format::BorderDashDotDot); format.setFillPattern(Format::PatternSolid); xlsx1.write("A2", QVariant(), format); xlsx1.saveAs(&device); device.open(QIODevice::ReadOnly); Document xlsx2(&device); QVERIFY(xlsx2.cellAt("A1")); QCOMPARE(xlsx2.cellAt("A1")->dataType(), Cell::Blank); QVERIFY(!xlsx2.cellAt("A1")->value().isValid()); QVERIFY(xlsx2.cellAt("A2")); QCOMPARE(xlsx2.cellAt("A2")->dataType(), Cell::Blank); QVERIFY(!xlsx2.cellAt("A2")->value().isValid()); QVERIFY(xlsx2.cellAt("A2")->format().isValid()); QCOMPARE(xlsx2.cellAt("A2")->format(), format); }
// The pixel aspect ratio of the current project double OfxImageEffectInstance::getProjectPixelAspectRatio() const { assert(_node); Format f; _node->getRenderFormat(&f); return f.getPixelAspect(); }
// The offset of the current project in canonical coordinates. // The offset is related to the kOfxImageEffectPropProjectSize and is the offset from the origin // of the project 'subwindow'. For example for a PAL SD project that is in letterbox form, the // project offset is the offset to the bottom left hand corner of the letter box. The project // offset is in canonical coordinates. void OfxImageEffectInstance::getProjectOffset(double& xOffset, double& yOffset) const { Format f; _node->getRenderFormat(&f); xOffset = f.left(); yOffset = f.bottom(); }
// The extent of the current project in canonical coordinates. // The extent is the size of the 'output' for the current project. See ProjectCoordinateSystems // for more infomation on the project extent. The extent is in canonical coordinates and only // returns the top right position, as the extent is always rooted at 0,0. For example a PAL SD // project would have an extent of 768, 576. void OfxImageEffectInstance::getProjectExtent(double& xSize, double& ySize) const { Format f; _node->getRenderFormat(&f); xSize = f.right(); ySize = f.top(); }
// finds the maximum/minimum values in the disparity channel // @todo: adjust to get x max/min and y max/min void findMaxMin(){ Guard guard(_lock); if (_firstTime){ Format format = input0().format(); const int fx = format.x(); const int fy = format.y(); const int fr = format.r(); const int ft = format.t(); ChannelSet dchan; for (int i=0; i < 4; i++){ dchan += dispChans[i]; } Interest interest(input0(), fx, fy, fr, ft, dchan, true); interest.unlock(); for (int y=fy; y < ft; y++){ progressFraction(y, ft - fy); Row row(fx, fr); if (aborted()) return; foreach (z, dchan) { row.get(input0(), y, fx, fr, z); const float *cur = row[z] + fx; const float *end = row[z] + fr; while (cur < end){ _maxValue = std::max((float)*cur, _maxValue); _minValue = std::min((float)*cur, _minValue); cur++; } } } _firstTime = false; }
static void report_stats(Timer &t, const NodePool &p) { t.stop(); Format f = "Path found in {} seconds"; info(f.bind(t.value())); f = "Pool allocated {} nodes ({} in trash)"; info(f.bind(p.allocated(), p.trashed())); }
/*! Finds the maximum and minimum pixel value for the frame in the mask channel * This is then used to determine the maximum size of the bbox and vertical tile */ void findMaxMin(){ Guard guard(_lock); if (_firstTime){ Format format = input0().format(); const int fx = format.x(); const int fy = format.y(); const int fr = format.r(); const int ft = format.t(); Channel mchan(*maskChan); Interest interest(input0(), fx, fy, fr, ft, mchan, true); interest.unlock(); _maxValue = 0.0; for (int y = fy; y < ft; y++){ progressFraction(y, ft - fy); Row row(fx, fr); row.get(input0(), y, fx, fr, mchan); if (aborted()) return; const float *cur = row[mchan] + fx; const float *end = row[mchan] + fr; while (cur < end){ _maxValue = std::max((float)fabs((float)*cur), _maxValue); cur++; } } _firstTime = false; } }
IECore::ImagePrimitivePtr ImagePlug::image() const { Format format = formatPlug()->getValue(); Box2i dataWindow = dataWindowPlug()->getValue(); Box2i newDataWindow( Imath::V2i(0) ); if( dataWindow.isEmpty() ) { dataWindow = Box2i( Imath::V2i(0) ); } else { newDataWindow = format.yDownToFormatSpace( dataWindow ); } ImagePrimitivePtr result = new ImagePrimitive( newDataWindow, format.getDisplayWindow() ); ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue(); const vector<string> &channelNames = channelNamesData->readable(); vector<float *> imageChannelData; for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ ) { FloatVectorDataPtr cd = new FloatVectorData; vector<float> &c = cd->writable(); c.resize( result->variableSize( PrimitiveVariable::Vertex ), 0.0f ); result->variables[*it] = PrimitiveVariable( PrimitiveVariable::Vertex, cd ); imageChannelData.push_back( &(c[0]) ); } parallel_for( blocked_range2d<size_t>( 0, dataWindow.size().x+1, tileSize(), 0, dataWindow.size().y+1, tileSize() ), GafferImage::Detail::CopyTiles( imageChannelData, channelNames, channelDataPlug(), dataWindow, Context::current(), tileSize()) ); return result; }
bool OutputEffectInstance::ifInfiniteclipRectToProjectDefault(RectD* rod) const { if ( !getApp()->getProject() ) { return false; } /*If the rod is infinite clip it to the project's default*/ Format projectDefault; getRenderFormat(&projectDefault); // BE CAREFUL: // std::numeric_limits<int>::infinity() does not exist (check std::numeric_limits<int>::has_infinity) // an int can not be equal to (or compared to) std::numeric_limits<double>::infinity() bool isRodProjectFormat = false; if (rod->left() <= kOfxFlagInfiniteMin) { rod->set_left( projectDefault.left() ); isRodProjectFormat = true; } if (rod->bottom() <= kOfxFlagInfiniteMin) { rod->set_bottom( projectDefault.bottom() ); isRodProjectFormat = true; } if (rod->right() >= kOfxFlagInfiniteMax) { rod->set_right( projectDefault.right() ); isRodProjectFormat = true; } if (rod->top() >= kOfxFlagInfiniteMax) { rod->set_top( projectDefault.top() ); isRodProjectFormat = true; } return isRodProjectFormat; }
bool Framebuffer::setDepthStencilBuffer(const TexturePointer& texture, const Format& format, uint32 subresource) { ++_depthStamp; if (isSwapchain()) { return false; } // Check for the compatibility of size if (texture) { if (!validateTargetCompatibility(*texture)) { return false; } } updateSize(texture); // assign the new one _depthStencilBuffer = TextureView(texture, subresource, format); _bufferMask = ( _bufferMask & ~BUFFER_DEPTHSTENCIL); if (texture) { if (format.getSemantic() == gpu::DEPTH) { _bufferMask |= BUFFER_DEPTH; } else if (format.getSemantic() == gpu::STENCIL) { _bufferMask |= BUFFER_STENCIL; } else if (format.getSemantic() == gpu::DEPTH_STENCIL) { _bufferMask |= BUFFER_DEPTHSTENCIL; } } return true; }
void Xlsxcontrol::writeInternalNumFormatsCell(Document &xlsx, int row, double value, int numFmt) { Format format; format.setNumberFormatIndex(numFmt); xlsx.write(row, 1, value); xlsx.write(row, 2, QString("Builtin NumFmt %1").arg(numFmt)); xlsx.write(row, 3, value, format); }
// The size of the current project in canonical coordinates. // The size of a project is a sub set of the kOfxImageEffectPropProjectExtent. For example a // project may be a PAL SD project, but only be a letter-box within that. The project size is // the size of this sub window. void OfxImageEffectInstance::getProjectSize(double& xSize, double& ySize) const { Format f; _node->getRenderFormat(&f); xSize = f.width(); ySize = f.height(); }
void _validate(bool for_real) { Format f = input0().format(); double _aspect = float(f.width()) / float(f.height()) * f.pixel_aspect(); distorter.set_aspect(_aspect); distorter.recompute_if_needed(); Material::_validate(for_real); }
void Xlsxcontrol::writeCustomNumFormatsCell(Document &xlsx, int row, double value, const QString &numFmt) { Format format; format.setNumberFormat(numFmt); xlsx.write(row, 1, value); xlsx.write(row, 2, numFmt); xlsx.write(row, 3, value, format); }