StreamingSounds(int argc, const char * argv[]) : UnitTest(argc, argv)
    {
        vector<string> files;
    
        string dirIn = stringOption(options, "dirIn");
        string dirOut = stringOption(options, "dirOut");
        string extension = stringOption(options, "ext");

        string fileIn = "";
        string fileOut = "";
    
        findFiles(dirIn, files, extension);
        
        for (vector<string>::iterator i = files.begin(); i != files.end(); ++i)
        {
            fileIn = *i;
            fileOut = fileIn.substr(0, fileIn.find_first_of('.')) + ".swf";

            cout << fileIn << endl;

    #ifdef WIN32
            fileOut = dirOut + "\\" + fileOut;
    #else
            fileOut = dirOut + "/" + fileOut;
    #endif

            try 
            {
                FSMovie movie;
                FSSoundConstructor* soundGenerator = SoundConstructor();
                
                if (soundGenerator->setSoundFromFile(fileIn.c_str()) != TransformUtil::OK)
                {
                    throw FSException("Could not load sound file");
                }

                float framesPerSecond = 12.0f;

                movie.setFrameSize(FSBounds(0, 0, 8000, 4000));
                movie.setFrameRate(framesPerSecond);
            
                movie.add(new FSSetBackgroundColor(FSColorTable::lightblue()));

                /*
                * Calculate the time it takes to play the sound and the number of frames this
                * represents.
                */
                float duration = ((float) soundGenerator->getSamplesPerChannel()) / ((float) soundGenerator->getSampleRate());
                int numberOfFrames = (int) (duration * framesPerSecond);
                
                /*
                * Play the Streaming Sound.
                *
                * Calculate the number of decoded sound samples played for each frame and
                * the size, in bytes, of each block compressed sound data.
                */
                int samplesPerBlock = soundGenerator->getSampleRate() / (int) framesPerSecond;
                int numberOfBlocks = soundGenerator->getSamplesPerChannel() / samplesPerBlock;

                /* 
                * An FSSoundStreamHeader2 object defines the attributes of the streaming sound.
		        */
                movie.add(soundGenerator->streamHeader(samplesPerBlock));

                /* 
                * Add a streaming block for each frame so the sound is played as each frame 
                * is displayed.
                */
                for (int i=0; i<numberOfBlocks; i++)
                {
                    movie.add(soundGenerator->streamBlock(i, samplesPerBlock));
                    movie.add(new FSShowFrame());
                }
		        movie.encodeToFile(fileOut.c_str());

                delete soundGenerator;
            }
            catch (FSException e)
            {
                cerr << e.what();
            }
        }
    }
Example #2
0
	StreamingSounds(map< string, string>& options)
	{
		string soundFile = stringOption(options, "file");

		FSSoundConstructor* soundGenerator = SoundConstructor();
		FSMovie movie;

		int status = TransformUtil::OK;

		if ((status = soundGenerator->setSoundFromFile(soundFile.c_str())) != TransformUtil::OK)
		{
			switch (status)
			{
				case TransformUtil::FileNotFound:
					cout << "Could not find sound file" << endl; break;
				case TransformUtil::ReadError:
					cout << "Could not read sound file" << endl; break;
				case TransformUtil::FormatError:
					cout << "Could not read sound file" << endl; break;
			}
		}

		if (status == TransformUtil::OK) 
		{
			float framesPerSecond = 12.0f;

			/*
			* Calculate the time it takes to play the sound and the number of frames 
			* this represents.
			*/
			float duration = ((float) soundGenerator->getSamplesPerChannel()) / 
				((float) soundGenerator->getSampleRate());
	            
			int numberOfFrames = (int) (duration * framesPerSecond);
	        
			/*
			* Calculate the number of decoded sound samples played for each frame and
			* the size, in bytes, of each block compressed sound data.
			*/
			int samplesPerBlock = soundGenerator->getSampleRate() / (int) framesPerSecond;
			int numberOfBlocks = soundGenerator->getSamplesPerChannel() / samplesPerBlock;

			/* 
			* Add all the objects together to create the movie.
			*/
			movie.setFrameSize(FSBounds(0, 0, 8000, 4000));
			movie.setFrameRate(framesPerSecond);
			movie.add(new FSSetBackgroundColor(FSColorTable::lightblue()));

			/* 
			* An FSSoundStreamHeader2 object defines the attributes of the streaming sound.
			*/
			movie.add(soundGenerator->streamHeader(samplesPerBlock));

			/* 
			* Add a streaming block for each frame so the sound is played as each frame 
			* is displayed.
			*/
			for (int i=0; i<numberOfBlocks; i++)
			{
				movie.add(soundGenerator->streamBlock(i, samplesPerBlock));
				movie.add(new FSShowFrame());
			}
	        
			saveMovie(movie, stringOption(options, "resultDir"), "StreamingSounds.swf");
		}
		delete soundGenerator;
	}
Example #3
0
    FillStyles(map< string, string>& options)
    {
        FSMovie movie;

        int width = 3600;
        int height = 2700;

        string imageFile = stringOption(options, "image");

        /*
        * A row of five rectangles will be displayed - one for each fill style.
        * The additional space is ued to provide padding between the rectangles 
        * and to the edge of the screen.
        */
        movie.setFrameSize(FSBounds(0, 0, (width+800)*5 , height+800));
        movie.setFrameRate(1.0f);
        movie.add(new FSSetBackgroundColor(FSColorTable::lightblue()));

        /*
        * Define the rectangle that is filled with the different fill styles.
        */
        FSBounds bounds(-width/2, -height/2, width/2, height/2);

        FSShape rectangle;

        rectangle.add(new FSShapeStyle(1, 1, 0, -width/2, -height/2));
        rectangle.add(new FSLine(width, 0));
        rectangle.add(new FSLine(0, height));
        rectangle.add(new FSLine(-width, 0));
        rectangle.add(new FSLine(0, -height));

        /*
        * The following variables are reused for each fill style to simplify the code.
        * In Transform an object assumes ownership for any added to it, so the shape
        * and style arrays can be safely reused in the FSDefineShape constructor. A 
        * shallow copy of the object is made. The FSDefineShape object assumes 
        * ownership of the objects they contain and no explicit memory management 
        * is required - the objects will be deleted when the shape is deleted.
        */

        int identifier = 0;
        
        FSShape shape;
        
        FSVector<FSLineStyle*> lineStyles(1);
        FSVector<FSFillStyle*> fillStyles(1);

        /*************************************************
        * Create a rectangle filled with a solid colour.
        *************************************************/
        shape = rectangle;
        identifier = movie.newIdentifier();
        
        lineStyles[0] = new FSSolidLine(20, FSColorTable::black());
        fillStyles[0] = new FSSolidFill(FSColorTable::red());

        movie.add(new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape));
        movie.add(new FSPlaceObject(identifier, 1, 2000, 1600));

        /******************************************
        * Create a rectangle tiled with an image.
        ******************************************/
        shape = rectangle;
        identifier = movie.newIdentifier();

        lineStyles[0] = new FSSolidLine(20, FSColorTable::black());

        try 
        {
            size_t size = 0;
            byte* bytes = dataFromFile(imageFile.c_str(), size);

            FSDefineJPEGImage* image = new FSDefineJPEGImage(movie.newIdentifier(), bytes, size);

            /*
            * Scale the loaded image to half its original size so it will tile four times inside the
            * rectangle. When an image is loaded its width and height default to twips rather than
            * pixels. An image 300 x 200 pixels will be displayed as 300 x 200 twips (15 x 10 pixels).
            * Scaling the image by 20 (20 twips = 1 pixel) would restore it to its original size. Here
            * we only scale the image to half its original size so variable sized images passed on the 
            * command line when the example is run are more easily seen.
            *
            * The coordinate transform relocates the top left corner of the image to the top left
            * corner of the rectangle in which it is displayed.
            */
            FSCoordTransform transform = FSCoordTransform(-width/2, -height/2, 10.0, 10.0);

            fillStyles[0] = new FSBitmapFill(FSFillStyle::TiledBitmap, image->getIdentifier(), transform);

            movie.add(image);
            movie.add(new FSJPEGEncodingTable()); // The image will still be displayed with an empty table
            movie.add(new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape));
            movie.add(new FSPlaceObject(identifier, 2, 6000, 1600));
        }
        catch (FSFileOpenException e)
        {
            cerr << e.what();
        }
        catch (FSAccessException e)
        {
            cerr << e.what();
        }

        /**************************************************
        * Create a rectangle filled with a clipped image.
        **************************************************/
        shape = rectangle;
        identifier = movie.newIdentifier();

        lineStyles[0] = new FSSolidLine(20, FSColorTable::black());

        try
        {
            size_t size = 0;
            byte* bytes = dataFromFile(imageFile.c_str(), size);

            FSDefineJPEGImage* image = new FSDefineJPEGImage(movie.newIdentifier(), bytes, size);

            /*
            * Scale the loaded image to half its original size so variable sized images are 
            * more easily seen. The coordinate transformation, taking into account the scaling
            * factor will display the image centered in the middle of the rectangle.
            */
            FSCoordTransform transform = FSCoordTransform(-(image->getWidth()*10)/2, -(image->getHeight()*10)/2, 10.0, 10.0);

            fillStyles[0] = new FSBitmapFill(FSFillStyle::ClippedBitmap, image->getIdentifier(), transform);

            movie.add(image);
            movie.add(new FSJPEGEncodingTable()); // The image will still be displayed with an empty table
            movie.add(new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape));
            movie.add(new FSPlaceObject(identifier, 3, 10000, 1600));
        }
        catch (FSFileOpenException e)
        {
            cerr << e.what();
        }
        catch (FSAccessException e)
        {
            cerr << e.what();
        }

        /*********************************************************
        * Create a rectangle filled with linear gradient colour.
        *********************************************************/
        shape = rectangle;
        identifier = movie.newIdentifier();

        /*
        * The gradient square must be mapped to the rectangle being filled. The square
        * measures 32768 x 32768 twips. The coordinates range from -16384, -16384 at the
        * bottom left corner to (16384, 16384) at the top right corner. Mapping takes place
        * in three steps:
        *
        * 1. The coordinate system of the gradient square is translated to match the coordinate
        * system of the shape in which the gradient is displayed. In this example, both the
        * gradient square and the rectangle in which it will be displayed are both centred at
        * (0,0) - see the FSBounds object created above. For this example the full range of the
        * gradient will be displayed so no translation is required. The second example that
        * displays a radial gradient illustrates how the translation can be calculated to change
        * the portion of the gradient being displayed.
        *
        * 2. The gradient square is scaled so that the full range of the gradient will be
        * displayed inside the rectangle. If a smaller scaling factor is set then the
        * portion of the gradient being displayed will change. The second example shows 
        * how the scaling factor affects the gradient.
        *
        * 3. The gradient can be rotated to change the direction of the colour change. If a
        * rotation is not applied then the gradient changes in the positive x axis - front left
        * to right on the Flash Player's screen.
        */

        // To display the full gradient, calculate the ratio of the shape's width to the width
        // of the gradient square. The gradient will be rotated so the width is used rather than
        // calculating the length of the diagonal.
        
        float scale = bounds.getWidth() / 32768.0f;

        // Since the centre of the rectangle and the gradient square are both at (0,0) no
        // additional translation is required.

        int translateX = 0;
        int translateY = 0;

        // The order of composition is important. If the scale transform was the first argument
        // then the translation coordinates would also be scaled.

        // The scaling is performed in the x and y direction as the gradient is rotated in the
        // the following step.
        
        FSCoordTransform transform = FSCoordTransform(translateX, translateY, scale, scale);

        // Apply a rotation so the gradient changes across the diagonal of the rectangle.
        
        transform.rotate(45);

        /*
        * The array of FSGradient objects defines how the colour changes across the gradient
        * square. The ratio defines the proportion across the square: 0 is the left side and
        * 255 is the right side.
        */
        FSVector<FSGradient> gradients(2);

        gradients[0] = FSGradient(0, FSColorTable::white());
        gradients[1] = FSGradient(255, FSColorTable::black());

        lineStyles[0] = new FSSolidLine(20, FSColorTable::black());
        fillStyles[0] = new FSGradientFill(FSFillStyle::LinearGradient, transform, gradients);

        movie.add(new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape));
        movie.add(new FSPlaceObject(identifier, 4, 14000, 1600));

        /*********************************************************
        * Create a rectangle filled with radial gradient colour.
        *********************************************************/
        shape = rectangle;
        identifier = movie.newIdentifier();

        // Resize the gradients array so the gradient will contain 4 colours.
        
        gradients.resize(4);

        /* The gradient will be centred in the bottom left corner of the rectangle
        * since the full spectrum of the radial gradient will be displayed the
        * gradient square need only be scaled by half the amount compared to the
        * linear gradient above.
        */
        float scaleX = (bounds.getWidth() / 32768.0f) * 2.0f;
        float scaleY = (bounds.getHeight() / 32768.0f) * 2.0f;

        /* Here the translation is calculated so the centre is expressed as a percentage
        * of the width of the rectangle. The general form of the calculation is:
        *
        * translateX = bounds.getMinX() + bounds.getWidth() * 0.0;
        * translateY = bounds.getMinY() + bounds.getHeight() * 0.25;
        */

        translateX = bounds.getMinX();
        translateY = bounds.getMinY();

        transform = FSCoordTransform(translateX, translateY, scaleX, scaleY);
        
        gradients[0] = FSGradient(15, FSColorTable::red());
        gradients[1] = FSGradient(63, FSColorTable::orange());
        gradients[2] = FSGradient(127, FSColorTable::yellow());
        gradients[3] = FSGradient(255, FSColorTable::green());

        lineStyles[0] = new FSSolidLine(1, FSColorTable::black());
        fillStyles[0] = new FSGradientFill(FSFillStyle::RadialGradient, transform, gradients);

        movie.add(new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape));
        movie.add(new FSPlaceObject(identifier, 5, 18000, 1600));

        movie.add(new FSShowFrame());

        saveMovie(movie, stringOption(options, "resultDir"), "FillStyles.swf");
    }
Example #4
0
/*!
    \fn F4lmDoc::slotfileExportMovie()
 */
void F4lmDoc::slotfileExportMovie()
{
  F4lmView *view=pViewList->first();
  CListViewItem *tmpListViewItem=(CListViewItem*)view->dad->tl->timeLineListbox->selectedItem();
  int animX=view->dad->tl->layerFrames->at(tmpListViewItem->m_Row-1)->frames->last ()->tableItemNo;
  int z=-1*tmpListViewItem->m_Row;



  int xLower = 000;
  int yLower = 000;
  int xUpper = view->defSceneRect.x()*2+600;
  int yUpper = view->defSceneRect.y()*2+600;

  FSMovie movie;
  movie.setFrameSize(FSBounds(xLower, yLower, xUpper, yUpper));
  /*
  * Set the frame rate at which the movie will be played.
  */
  float framesPerSecond = 25.0f;

  movie.setFrameRate(framesPerSecond);
  /*
  * Set the movie's background colour to light blue. The background colour
  * only be set once and should be the first object added to a movie. If no
  * background colour is specified then the Flash Player will set it to white.
  */
  /// TODO:defscenerect should be color here.
  movie.add(new FSSetBackgroundColor(FSColorTable::white()));


  for(int i=0;i<=view->dad->tl->layerMaxColNum;i++)
  {
    Q3CanvasItemList l=view->mainCanvas->allItems();
    for (Q3CanvasItemList::Iterator it = l.begin (); it != l.end ();++it)
    {
      if ((*it)->rtti () == 666 || (*it)->rtti () == 667)
      {		//should not be output object types.
        continue;
      }
      switch((*it)->rtti())
      {
      case Q3CanvasItem::Rtti_Ellipse:
        {
          CCanvasEllipse *oval=(CCanvasEllipse*)(*it);
          if(oval->animationX>=i)continue;
          FSShapeConstructor* path = ShapeConstructor(); //buundan circle cikar
          //path->COORDINATES_ARE_PIXELS = true;
          int width = oval->width();
          int height = oval->height();
          int identifier = movie.newIdentifier();

          QColor PenColor=oval->pen().color();
          QColor BrushColor=oval->brush().color();
          FSSolidLine* lineStyle = new FSSolidLine(1,  FSColor(PenColor.red(),PenColor.green(),PenColor.blue()));
          FSSolidFill* fillStyle =new FSSolidFill(FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue()));
          path->addLineStyle(lineStyle);
          path->addFillStyle(fillStyle);

          //delete lineStyle;
          //delete fillStyle;
          //path->newPath();                   // start a new path
          //path->selectStyle(1, 1);       // select the first line and fill style objects
          //path->move(-width/2, -height/2);
          //path->closePath();
          path->ellipse(-width/2, -height/2, width/2, height/2);
          movie.add(path->defineShape(identifier));
          movie.add(new FSPlaceObject(identifier, oval->Row, oval->x(), oval->y()));

          movie.add(new FSShowFrame());
        }
        break;
      case Q3CanvasItem::Rtti_Line:
        {
          CCanvasLine *line=(CCanvasLine*)(*it);
          //qDebug("frame %d",i);
          if(line->animationX>=i)continue;

          int identifier = movie.newIdentifier();

          int width = (line->startPoint().x()-line->endPoint().x());
          int height = (line->startPoint().y()-line->endPoint().y());
          //qDebug("startX: %d height: %d",line->startPoint().x(),line->endPoint().x());
          FSBounds bounds(-width, -height, width, height);
          //qDebug("width: %d height: %d",width,height);
          FSVector<FSLineStyle*> lineStyles(1);
          FSVector<FSFillStyle*> fillStyles(1);

          QColor PenColor=line->pen().color();
          QColor BrushColor=line->brush().color();
          //qDebug("renk ismi %d %d %d",BrushColor.red(),BrushColor.green(),BrushColor.blue());
          lineStyles[0] = new FSSolidLine(1, FSColor(PenColor.red(),PenColor.green(),PenColor.blue()));
          fillStyles[0] = new FSSolidFill( FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue()));

          FSShape shape;
          shape.add(new FSShapeStyle(1, 1, 0,-width/2,-height/2));
          //shape.add(new FSShapeStyle(line->startPoint().x(), line->startPoint().y()));
          //shape.add(new FSLine(line->startPoint().x(),line->startPoint().y()));
          //shape.add(new FSLine(line->endPoint().x(),line->endPoint().y()));
          shape.add(new FSLine(-width, -height));
          shape.add(new FSLine(width, height));
          /*shape.add(new FSLine(-width, 0));
          shape.add(new FSLine(0, -height));*/
          FSDefineShape* Line = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape);

          movie.add(Line);

          movie.add(new FSPlaceObject(identifier, line->Row, line->startPoint().x(), line->startPoint().y()));

          movie.add(new FSShowFrame());
        }
        break;
      case Q3CanvasItem::Rtti_Polygon:

        break;
      case Q3CanvasItem::Rtti_PolygonalItem:
        {
          CPencilLine *poly=(CPencilLine*)(*it);
        }

        break;
      case Q3CanvasItem::Rtti_Rectangle:
        {
          CCanvasRectangle *rect=(CCanvasRectangle*)(*it);
          //qDebug("rect animx : %d colon numaramiz: %d",rect->animationX,i);
          if(rect->animationX>=i)continue;

          int identifier = movie.newIdentifier();

          int width = rect->width();
          int height =rect->height();

          FSBounds bounds(-width,-height, width, height);

          FSVector<FSLineStyle*> lineStyles(1);
          FSVector<FSFillStyle*> fillStyles(1);

          QColor PenColor=rect->pen().color();
          QColor BrushColor=rect->brush().color();
          lineStyles[0] = new FSSolidLine(1, FSColor(PenColor.red(),PenColor.green(),PenColor.blue()));
          fillStyles[0] = new FSSolidFill( FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue()));
          /*
          * Create the outline of the shape. All drawing is performed using a series
          * of line an curve objects. The FSShapeStyle class is used to select the 
          * current line and fill styles and to perform absolute moves within the 
          * coordinate space of the shape (relative moves can be performed by drawing
          * line when no line style is selected - set the line style to 0).
          */

          FSShape shape;

          shape.add(new FSShapeStyle(0, 1, 0,-width/2,-height/2));
          //qDebug("width %d height %d baslangicX:%d baslangicY:%d",width,height,rect->rect().x() - view->defSceneWidth,rect->rect().y()-view->defSceneHeight);
          //shape.add(new FSShapeStyle(0,0));
          shape.add(new FSLine(width, 0));
          shape.add(new FSLine(0, height));
          shape.add(new FSLine(-width, 0));
          shape.add(new FSLine(0, -height));

          /*shape.add(new FSShapeStyle(1, 1, 0,-50,-50));
          shape.add(new FSLine(100,0));
          shape.add(new FSLine(0,100));
          shape.add(new FSLine(-100,0));
          shape.add(new FSLine(0,-100));*/

          FSDefineShape* rectangle = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape);

          /*
          * Add the rectangle to the movie. All shapes and objects must be defined before
          * they can be placed on the display list and rendered on the Flash Player's
          * screen.
          */
          movie.add(rectangle);

          /*
          * for layers and object place.
          */
          movie.add(new FSPlaceObject(identifier, rect->Row, rect->rect().x(), rect->rect().y()));

          /*
          * Show the contents of the display list. Frames are delimited by successive
          * FSShowFrame objects.
          */
          movie.add(new FSShowFrame());
        }
        break;
      case Q3CanvasItem::Rtti_Spline:
        break;
      case Q3CanvasItem::Rtti_Sprite:
        {
          Q3CanvasSprite *sprite=(Q3CanvasSprite*)(*it);
          QByteArray ba;
          QBuffer buffer( &ba );
          buffer.open( QIODevice::WriteOnly );
sprite->image()->convertToImage().save( &buffer, "BMP" ); // writes image into ba in BMP format
          FSImageConstructor* imageGenerator = ImageConstructor();
          int status = TransformUtil::OK;
int boyutu=ba.size();
qDebug("%d",boyutu);
          //if ((status = imageGenerator->setImageFromFile(imageFile.c_str())) != TransformUtil::OK)(  const unsigned char *)
          //if ((status = imageGenerator->setImage(sprite->image()->convertToImage ().bits(),sizeof(sprite->image()->convertToImage ().bits()))) != TransformUtil::OK)
if ((status = imageGenerator->setImage((const unsigned char*)buffer.buffer().data(),sizeof(char)*boyutu)) != TransformUtil::OK)
          {
            switch (status)
            {
            case TransformUtil::FileNotFound:
              cout << "Could not find image" << endl; break;
            case TransformUtil::ReadError:
              cout << "Could not read image" << endl; break;
            case TransformUtil::FormatError:
              cout << "Could not read image" << endl; break;
            }
          }
          if (status == TransformUtil::OK)
          {
            /*
            * Create the FSImageConstructor object used to generate the object
            * containing the image definition. Initialize it using the name of 
            * the image file passed on the command line when the example was run.
            */

            int imageId = movie.newIdentifier();
            int shapeId = movie.newIdentifier();

            int xOrigin = imageGenerator->getWidth()/2;
            int yOrigin = imageGenerator->getHeight()/2;

            FSDefineObject* image = imageGenerator->defineImage(imageId);

            /*
            * All images must be displayed as a bitmap fill inside a shape. The 
            * FSImageConstructor class generates the shape enclosing the image.
            * If no border is required then the line style may be set to null.
            */
            int borderWidth = 20;
            FSColor black = FSColorTable::black();

            FSDefineShape3* shape = imageGenerator->defineShape(shapeId, imageId,
                                    -xOrigin, -yOrigin, borderWidth, &black);

            /*
            * Add all the objects together to create the movie.
            */
            movie.setFrameRate(1.0f);
            movie.setFrameSize(shape->getBounds());
            movie.add(image);
            movie.add(shape);
            movie.add(new FSPlaceObject2(shapeId, 1, 0, 0));
            movie.add(new FSShowFrame());

          }

        }
        break;
      case Q3CanvasItem::Rtti_Text:
        {
          CCanvasText *canvasText=(CCanvasText*)(*it);
          if(canvasText->animationX>=i)continue;
          FSTextConstructor* textGenerator = TextConstructor();
          int status = TransformUtil::OK;
          proc = new Q3Process();
          proc->addArgument( "locate");
          proc->addArgument("*.ttf");
          QString buf;
          //proc->launch(buf);
          connect( proc, SIGNAL(readyReadStdout()),
                   this, SLOT(readFromStdout()) );

          if ( !proc->start() )
          {
            // error handling
            qDebug("process could not started.");
            return;
          }
          while(proc->isRunning()==TRUE){qApp->processEvents();}
          /*QByteArray bufByte=proc->readStdout();
          if(!proc->normalExit())
          	qDebug("%d",proc->exitStatus ());
          QString sttir(bufByte);
          QStringList sittirList;*/
          QString ttfFileName="";
          qDebug(canvasText->font().family().stripWhiteSpace ());
          procOut = procOut.split("\n",procOut.join("\n"));
          qDebug("%d",procOut.count());
          for(int ttfIndis=0;ttfIndis<procOut.count();ttfIndis++)
          {
            if(procOut[ttfIndis].right(4)==".ttf")
            {
              //qDebug(procOut[ttfIndis]);
              if(procOut[ttfIndis].contains(canvasText->font().family().stripWhiteSpace (),false))
              {
                //qDebug("burasi ana yer");
                ttfFileName=procOut[ttfIndis];
                break;
              }
            }
            //qDebug("%d",ttfIndis);
            //qDebug(procOut[ttfIndis]);
          }
          if(ttfFileName=="")
          {
            qDebug("we could not find ttf file.");
            //TODO: for default font make an options dialog.
            qDebug("Default Font Selected.");
            for(int ttfIndis=0;ttfIndis<procOut.count();ttfIndis++)
            {
              if(procOut[ttfIndis].right(4)==".ttf")
              {
                //qDebug(procOut[ttfIndis]);
                //TODO:when you done option dialog for default font change the "arial" from down line.
                if(procOut[ttfIndis].contains("arial",false))
                {
                  ttfFileName=procOut[ttfIndis];
                  break;
                }
              }
            }
          }
          qDebug(ttfFileName);

          if ((status = textGenerator->setFontFromFile(ttfFileName)) != TransformUtil::OK)
          {
            switch (status)
            {
            case TransformUtil::FileNotFound:
              cout << "Could not find font file" << endl; break;
            case TransformUtil::ReadError:
              cout << "Could not read font file" << endl; break;
            case TransformUtil::FormatError:
              cout << "Could not read font file" << endl; break;
            }
          }
          int layer = 0;                // Starting layer for objects in the display list.
          int fontSize = canvasText->boundingRect().height(); // 280;           // Font size in twips 1 point = 20 twips
          int lineSpacing = fontSize;   // The font size defines a suitable line spacing

          /*
          * The movie will be sized to match the block of text generated.
          * The margins are defined so the text is displayed without touching
          * the edge of the Flash Player screen.
          */
          int leftMargin = fontSize;
          int rightMargin = fontSize;
          int topMargin = fontSize;
          int bottomMargin = fontSize;

          FSColor textColor(canvasText->color().red(),canvasText->color().green(),canvasText->color().blue());

          textGenerator->setIdentifier(movie.newIdentifier());
          textGenerator->setSize(fontSize);
          textGenerator->setColor(&textColor);

          /*
          * The block of text is generated before the font definition. This ensures
          * that only the characters displayed will be included in the font. Unused
          * characters will be omitted, greatly reducing the size of the Flash file
          * generated. Once the FSDefineFont2 object has been generated any text 
          * objects created with characters not previously used, will not be 
          * displayed correctly - a new font definition would need to be generated
          * to include the new characters.
          * 
          * The FSDefineText2 object contains an array of FSText objects, each
          * specifying an offset relative to the origin of the entire block. These
          * can easily be changed if a line needs to be indented or the line spacing
          * adjusted. 
          */
          //FSDefineText2* text = textGenerator->defineWideTextBlock(movie.newIdentifier(),
          //	(const wchar_t **)lines, 32, lineSpacing);
          FSDefineText2* text = textGenerator->defineText(movie.newIdentifier(),canvasText->text());

          FSDefineFont2* font = textGenerator->defineFont();

          /*
          * Define the size of the Flash Player screen using the bounding 
          * rectangle defined for the block of text plus a suitable margin so 
          * the text does not touch the edge of the screen.
          */
          int screenWidth = text->getBounds().getWidth() + leftMargin + rightMargin;
          int screenHeight = text->getBounds().getHeight() + topMargin + bottomMargin;

          movie.add(font);
          movie.add(text);
          movie.add(new FSPlaceObject2(text->getIdentifier(), canvasText->Row, canvasText->boundingRect ().x() , canvasText->boundingRect ().y()));
          movie.add(new FSShowFrame());

        }
        break;
      }
    }
  }
  try
  {
    QString fileName = Q3FileDialog::getSaveFileName( );
    movie.encodeToFile(fileName);

  }
  catch (FSException e)
  {
    /*
     * Several exceptions could be thrown to get to this point. FSMovie will 
     * throw an FSFileOpenException, FSAccessException or FSFormatException 
     * if the file cannot be opened for writing, an error occurs while writing
     * to the file or if an error occurs while encoding the Flash data, respectively.
     * 
     * All the exceptions thrown contain a message which describes why the
     * exception was thrown so handling them all in the same way is sufficient
     * for the purposes of the examples.
     */
    cerr << e.what();
  }
}
Example #5
0
    MovieBasics(map<string, string>& options)
    {
        FSMovie movie;

        /*
        * The movie bounds are specified in twips. The bounding rectangle is defined
        * by two points: the lower left corner and the upper right corner of the
        * rectangle that encloses the area.
        *
        * The bounding rectangle also defines the coordinate range for the x and y axes.
        * Here the coordinates for the x and y axes range from -4000 to +4000. A point with
        * the coordinates (0,0) lies in the center of the screen.
        *
        * If the coordinates of the corners were specified as (0,0) and (4000, 4000) the
        * size of the screen is still the same however the center of the screen now
        * lies at (2000,2000)
        */
        int xLower = -4000;
        int yLower = -4000;
        int xUpper = 4000;
        int yUpper = 4000;

        movie.setFrameSize(FSBounds(xLower, yLower, xUpper, yUpper));

        /*
        * Set the frame rate at which the movie will be played.
        */
        float framesPerSecond = 1.0f;

        movie.setFrameRate(framesPerSecond);

        /*
        * Set the movie's background colour to light blue. The background colour
        * only be set once and should be the first object added to a movie. If no
        * background colour is specified then the Flash Player will set it to white.
        */
        movie.add(new FSSetBackgroundColor(FSColorTable::lightblue()));

        /*
        * Define a shape to be displayed. Each object must be assigned a unique identifier
        * which is used to reference the object when adding, updating or removing it from
        * the display list. The movie object keeps track of the identifier to guarantee
        * each is unique.
        */
        int identifier = movie.newIdentifier();

        int width = 4000;
        int height = 4000;

        FSBounds bounds(-2000, -2000, 2000, 2000);

        FSVector<FSLineStyle*> lineStyles(1);
        FSVector<FSFillStyle*> fillStyles(1);

        lineStyles[0] = new FSSolidLine(20, FSColorTable::black());
        fillStyles[0] = new FSSolidFill(FSColorTable::red());

        /*
        * Create the outline of the shape. All drawing is performed using a series
        * of line an curve objects. The FSShapeStyle class is used to select the 
        * current line and fill styles and to perform absolute moves within the 
        * coordinate space of the shape (relative moves can be performed by drawing
        * line when no line style is selected - set the line style to 0).
        */

        FSShape shape;

        shape.add(new FSShapeStyle(1, 1, 0, -width/2, -height/2));
        shape.add(new FSLine(width, 0));
        shape.add(new FSLine(0, height));
        shape.add(new FSLine(-width, 0));
        shape.add(new FSLine(0, -height));

        FSDefineShape* rectangle = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape);

        /*
        * Add the rectangle to the movie. All shapes and objects must be defined before
        * they can be placed on the display list and rendered on the Flash Player's
        * screen.
        */
        movie.add(rectangle);

        /*
        * Place the shape on the display list. See the DisplayList example for the set of
        * objects that are used to add, update and remove objects from the display list.
        */      
        movie.add(new FSPlaceObject(identifier, 1, 0, 0));

        /*
        * Show the contents of the display list. Frames are delimited by successive
        * FSShowFrame objects.
        */
        movie.add(new FSShowFrame());

        saveMovie(movie, stringOption(options, "resultDir"), "MovieBasics.swf");
    }