Exemplo n.º 1
0
	void MainWindow::clearFontSelection() {

		fontPreviews()->removeTemporaryView();

		// Start unselecting fonts from the preview.
		while (not fontPreviews()->empty())
			fonts()->unselectFont(0);

		// Unmark remaining fonts which were not in the previews
		fonts()->unmarkAll();

		updateClearSelectionButton();

		document->font_search_proxy->showOnlySelected(false);
		showSelectedFontsCheckbox->setChecked(false);
	}
Exemplo n.º 2
0
const Font* FontImpl::lookup(Display* d, const String& name, float scale) {
    const Font* f;
    FontRep* r;
    KnownFonts* k = nil;
    UniqueString uname(name);
    if (fonts()->find(k, uname)) {
	for (ListItr(FontList) i(k->fonts); i.more(); i.next()) {
	    f = i.cur();
	    if (Math::equal(f->impl_->scale_, scale, float(0.0001))) {
		return f;
	    }
	}

	r = find_rep(k->fontreps, d, scale);
	if (r != nil) {
	    return new_font(uname, scale, k, r);
	}
    }

    r = create(d, uname, scale);
    if (r == nil) {
	return nil;
    }
    k = known(k, uname);
    f = new_font(uname, scale, k, r);
    f->impl_->new_rep(k, r);
    f->impl_->entry_ = k;
    return f;
}
Exemplo n.º 3
0
QString TPaths::fontPath() {

    QString path = fontPathPlayer(pref->player_bin);
    if (fonts(path).count() > 0) {
		return path;
    }

    if (pref->player_id == Settings::TPreferences::ID_MPLAYER) {
        path = fontPathPlayer(pref->mpv_bin);
    } else {
        path = fontPathPlayer(pref->mplayer_bin);
    }
    if (fonts(path).count() > 0) {
        return path;
    }
    return qApp->applicationDirPath() + "/open-fonts";
}
Exemplo n.º 4
0
FontRep* FontImpl::rep(Display* d) {
    FontRep* r;
    for (ListItr(FontRepList) i(*replist_); i.more(); i.next()) {
	r = i.cur();
	if (r->display_ == d) {
	    return r;
	}
    }

    KnownFonts* k = nil;
    if (fonts()->find(k, *name_)) {
	r = find_rep(k->fontreps, d, scale_);
	if (r != nil) {
	    attach(r);
	    return r;
	}
    }

    r = create(d, *name_, scale_);
    if (r != nil) {
	new_rep(known(k, *name_), r);
    }
    return r;
}
Exemplo n.º 5
0
int main(int argc,char** args) {

    srand(time(NULL));

    try {

        if (SDL_Init(SDL_INIT_VIDEO)) {
            fprintf(stderr,"Unable to initialize SDL: %s\n",SDL_GetError());
            return EXIT_FAILURE;
        }
        atexit(SDL_Quit);

        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
#if 0
        screen = SDL_SetVideoMode(1440,900,32,SDL_OPENGL|SDL_FULLSCREEN);
#else
        screen = SDL_SetVideoMode(1024,768,32,SDL_OPENGL/*|SDL_FULLSCREEN*/);
#endif
        if(!screen) {
            fprintf(stderr,"Unable to create SDL screen: %s\n",SDL_GetError());
            return EXIT_FAILURE;
        }
        SDL_WM_SetCaption("GlestNG","GlestNG");

        GLenum err = glewInit();
        if(GLEW_OK != err) {
            fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
            return EXIT_FAILURE;
        }
        fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

        // we have a GL context so we can go ahead and init all the singletons
        std::auto_ptr<fs_t> fs_settings(fs_t::create("data/"));
        fs_t::settings = fs_settings.get(); // set it globally
        std::auto_ptr<xml_parser_t> xml_settings(new xml_parser_t("UI Settings",fs_settings->get_body("ui_settings.xml")));
        xml_settings->set_as_settings();
        std::auto_ptr<graphics_t::mgr_t> graphics_mgr(graphics_t::create());
        std::auto_ptr<fonts_t> fonts(fonts_t::create());
        std::auto_ptr<fs_t> fs;
        try {
            fs.reset(fs_t::create("data/Glest"));
            if(false) {
                fs_file_t::ptr_t logo_file(fs_settings->get("logo.g3d"));
                istream_t::ptr_t logostream(logo_file->reader());
                logo = std::auto_ptr<model_g3d_t>(new model_g3d_t(*logostream));
            }
            load(*fs);
        } catch(glest_exception_t* e) {
            std::cerr << "cannot load glest data: " << e << std::endl;
            delete e;
        }
        std::auto_ptr<ui_mgr_t> ui_(ui_mgr());
        std::auto_ptr<mod_ui_t> mod_ui(mod_ui_t::create());

        std::auto_ptr<terrain_t> terrain(terrain_t::gen_planet(5,500,3));
        //world()->dump(std::cout);

        v4_t light_amb(0,0,0,1), light_dif(1.,1.,1.,1.), light_spec(1.,1.,1.,1.), light_pos(1.,1.,-1.,0.),
             mat_amb(.7,.7,.7,1.), mat_dif(.8,.8,.8,1.), mat_spec(1.,1.,1.,1.);
        glLightfv(GL_LIGHT0,GL_AMBIENT,light_amb.v);
        glLightfv(GL_LIGHT0,GL_DIFFUSE,light_dif.v);
        glLightfv(GL_LIGHT0,GL_SPECULAR,light_spec.v);
        glLightfv(GL_LIGHT0,GL_POSITION,light_pos.v);
        glLightfv(GL_LIGHT1,GL_AMBIENT,light_amb.v);
        glLightfv(GL_LIGHT1,GL_DIFFUSE,light_dif.v);
        glLightfv(GL_LIGHT1,GL_SPECULAR,light_spec.v);
        glMaterialfv(GL_FRONT,GL_AMBIENT,mat_amb.v);
        glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_dif.v);
        glMaterialfv(GL_FRONT,GL_SPECULAR,mat_spec.v);
        glMaterialf(GL_FRONT,GL_SHININESS,100.0);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHT1);
        glDepthFunc(GL_LEQUAL);
        glEnable(GL_DEPTH_TEST);
        glAlphaFunc(GL_GREATER,0.4);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_RESCALE_NORMAL);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_NORMALIZE);
        glFrontFace(GL_CW);
        camera();
        bool quit = false;
        SDL_Event event;
        SDL_EnableKeyRepeat(200,20);
        SDL_EnableUNICODE(true);
        const unsigned start = SDL_GetTicks();
        framerate.reset();
        while(!quit) {
            set_now(SDL_GetTicks()-start);
            while(!quit && SDL_PollEvent(&event)) {
                if(ui_mgr()->offer(event))
                    continue;
                switch (event.type) {
                case SDL_MOUSEMOTION:
                    if(selection)
                        std::cout << "drag" << std::endl;
                    /*printf("Mouse moved by %d,%d to (%d,%d)\n",
                    event.motion.xrel, event.motion.yrel,
                    event.motion.x, event.motion.y);*/
                    break;
                case SDL_MOUSEBUTTONDOWN:
                    click(event.button.x,event.button.y);
                    if(selection)
                        std::cout << "selection: "<<selected_point<<std::endl;
                    break;
                case SDL_MOUSEBUTTONUP:
                    if(selection)
                        std::cout << "selection stopped" << std::endl;
                    selection = false;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym) {
                    case SDLK_PLUS:
                        zoom += 1;
                        camera();
                        break;
                    case SDLK_MINUS:
                        zoom -= 1;
                        camera();
                        break;
                    case SDLK_ESCAPE:
                        quit = true;
                        break;
                    case SDLK_m: // MODDING MODE
                        if(!fs.get()) {
                            std::cerr << "(modding menu triggered but mod not loaded)" << std::endl;
                            break;
                        }
                        if(mod_ui->is_shown())
                            mod_ui->hide();
                        else
                            mod_ui->show(ref_t(*techtree,TECHTREE,techtree->name));
                        break;
                    default:
                        std::cout << "Ignoring key " <<
                                  (int)event.key.keysym.scancode << "," <<
                                  event.key.keysym.sym << "," <<
                                  event.key.keysym.mod << "," <<
                                  event.key.keysym.unicode << std::endl;
                    }
                    break;
                case SDL_QUIT:
                    quit = true;
                    break;
                }
            }
            framerate.tick(now());
            tick();
        }
        for(tests_t::iterator i=objs.begin(); i!=objs.end(); i++)
            delete *i;
        return EXIT_SUCCESS;
    } catch(data_error_t* de) {
        std::cerr << "Oh! " << de << std::endl;
    } catch(graphics_error_t* ge) {
        std::cerr << "Oh! " << ge << std::endl;
    } catch(panic_t* panic) {
        std::cerr << "Oh! " << panic << std::endl;
    }
    return EXIT_FAILURE;
}
Exemplo n.º 6
0
void Chicken::start()
{
    sf::Music music;
    if (!music.openFromFile("music/outlaw.ogg"))
    {
        return; // error
    }
    music.play();
    music.setLoop(true);

    sf::RenderWindow window(sf::VideoMode(C_X, C_Y), "I WANNA", sf::Style::Close);
    image.loadFromFile("textures/upIco.png");
    window.setIcon(179, 179, image.getPixelsPtr());

    sf::RenderWindow windowGuide(sf::VideoMode(500, 700), "Guide", sf::Style::Titlebar);
    windowGuide.setVisible(false);

    if (guide==true)
    {
        window.setPosition(sf::Vector2i(30, 30));
        windowGuide.setVisible(true);

        windowGuide.setPosition(sf::Vector2i(1370, 170));
        if (language == 1)
        {
            backgroundGuide.loadFromFile("textures/chickenRules.png");
        }
        else
        {
            backgroundGuide.loadFromFile("textures/engUpRules.png");
        }
        backgroundsprGuide.setTexture(backgroundGuide);
        windowGuide.draw(backgroundsprGuide);
        windowGuide.display();
    }

    ChickenDeck * myDeck = new ChickenDeck();
    myDeck->randomize();
    ChickenDeck * aiDeck = new ChickenDeck();
    aiDeck->randomizeNew();
    ChickenCard * middleCard = new ChickenCard();
    ChickenCard * myCard = new ChickenCard();
    ChickenCard * aiCard = new ChickenCard();
    ChickenNext * nextBtn = new ChickenNext();
    nextBtn->next();
    ChickenNext * message = new ChickenNext();

    ChickenBackCard * myDeckSkin = new ChickenBackCard();
    ChickenBackCard * aiDeckSkin = new ChickenBackCard();
    aiDeckSkin->sprite.setPosition(30, 30);
    myDeckSkin->sprite.setPosition(C_X-30-139, C_Y-30-216);
    aiDeckSkin->setTexture();
    myDeckSkin->setTexture();

    std::queue<ChickenCard> myQueue;
    std::queue<ChickenCard> aiQueue;

    int strokeman = getStrokeman();
    fonts(strokeman);

    for (int i=0; i<52; i++)
    {
        myQueue.push(myDeck->getCard());
        aiQueue.push(aiDeck->getCard());
    }
    bool compareB = false;
    bool start = true;
    bool middleVisible = false;
    int myPoints = 0, aiPoints = 0, wannaPoints = 1;
    char text[C_BUFFER] = "";
    int round = 1;
    int myQueueSize, aiQueueSize;
    bool finish = false;

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }
            if ((event.type == sf::Event::MouseButtonPressed)&&(event.mouseButton.button == sf::Mouse::Left))
            {
                if (nextBtn->isPressed(event.mouseButton.x, event.mouseButton.y) && (!finish))
                {
                    if (!start)
                    {
                        if (myPoints == wannaPoints && aiPoints == wannaPoints)
                        {
                            if (strokeman == PLAYER)
                            {
                                *middleCard = *myCard;
                                myQueue.pop();
                                aiQueue.push(aiQueue.front());
                                aiQueue.pop();
                                wannaPoints++;
                            }
                            else
                            {
                                *middleCard = *aiCard;
                                aiQueue.pop();
                                myQueue.push(myQueue.front());
                                myQueue.pop();
                                wannaPoints++;
                            }
                            middleVisible = true;
                        }
                        else if(myPoints == wannaPoints)
                        {
                            *middleCard = *myCard;
                            myQueue.pop();
                            aiQueue.push(aiQueue.front());
                            aiQueue.pop();
                            wannaPoints++;
                            middleVisible = true;
                        }
                        else if (aiPoints == wannaPoints)
                        {
                            *middleCard = *aiCard;
                            aiQueue.pop();
                            myQueue.push(myQueue.front());
                            myQueue.pop();
                            wannaPoints++;
                            middleVisible = true;
                        }
                        else
                        {
                            myQueue.push(myQueue.front());
                            myQueue.pop();
                            aiQueue.push(aiQueue.front());
                            aiQueue.pop();
                        }
                        if (middleVisible)
                        {
                            middleCard->setTexture();
                            middleCard->sprite.setPosition(430.5, C_Y-550);
                        }
                        if (wannaPoints==14)
                        {
                            round++;
                            wannaPoints = 1;
                            getRound(round);
                        }
                        sprintf(text, WANNACONST, getWannaText(wannaPoints));
                        wannaText.setString(text);
                        myQueueSize = myQueue.size();
                        sprintf(text, "%i", myQueueSize);
                        mySize.setString(text);
                        aiQueueSize = aiQueue.size();
                        sprintf(text, "%i", aiQueueSize);
                        aiSize.setString(text);
                        if (myQueueSize == 0 || aiQueueSize == 0)
                        {
                            finish = true;
                            if (myQueueSize == 0)
                            {
                                message->win();
                            }
                            else
                            {
                                message->lose();
                            }
                            break;
                        }
                    }
                    compareB = true;
                    start = false;
                    *myCard = myQueue.front();
                    *aiCard = aiQueue.front();
                    myCard->setTexture();
                    aiCard->setTexture();
                    myCard->sprite.setPosition(30, 30+216+30);
                    aiCard->sprite.setPosition(C_X-139-30, C_Y-30-216-216-30);
                    myPoints = myCard->getPoints();
                    aiPoints = aiCard->getPoints();
                    if (strokeman == PLAYER)
                    {
                        strokeman = AI;
                        strokeText.setString("Enemy stroke...");
                    }
                    else
                    {
                        strokeman = PLAYER;
                        strokeText.setString("Your stroke...");
                    }
                }
            }
        }
        window.clear(sf::Color(0,115,0));
        if (finish == true)
        {
            window.draw(message->sprite);
        }
        else
        {
            window.draw(backgroundspr);
            window.draw(myDeckSkin->sprite);
            window.draw(aiDeckSkin->sprite);
            if (compareB == true)
            {
                window.draw(myCard->sprite);
                window.draw(aiCard->sprite);
            }
            if (middleVisible)
            {
                window.draw(middleCard->sprite);
            }
            window.draw(nextBtn->sprite);
            window.draw(mySize);
            window.draw(aiSize);
            window.draw(wannaText);
            window.draw(strokeText);
            window.draw(myName);
            window.draw(aiName);
        }
        window.display();
    }
    return;
}
Exemplo n.º 7
0
/* parse_extend()
 * ====================================================================
 * Parse the EXTEND.SYS file to get the fonts...
 * ANother routine is used to parse and get the cache settings etc...
 * IN: int skip		0 - Don't skip anything, parse everything.
 *			    Used during a rez change or boot-up
 *			1 - Skip parsing the path. Used during a 
 *			    directory change.
 */
int
parse_extend( int skip )
{
    errno = 0;
    xopen( ExtendPath );

    /* Check to see if the file 'EXTEND.SYS' exists.
     */
    if( errno )
    {
        /* NO- Its NOT HERE!!! */
	/* There are NO Active Outline Fonts */
        if( !skip )	
        {
           sprintf( Current.FontPath, "%c:", Drive );
           
  	   /* set some defaults here ONLY when we are supposed
  	    * to parse EVERYTHING. This way when we are only 
  	    * switching directories, the current values are 
  	    * NOT affected.
  	    */
	   Current.SpeedoCacheSize = 100L;	/* Set to 100K */
	   Current.BitMapCacheSize = 100L;
	   Current.speedo_percent  = 5;	/* Set to 50% */
           Current.point_size[0] = 10;
        }     
	return( errno );
    }

    if( !skip )
    {
       strcpy( Current.FontPath, OutlinePath );
       Current.SpeedoCacheSize = 0L;
       Current.BitMapCacheSize = 0L;
       Current.speedo_percent = 5;	/* 50% */
       Current.Width = 0;
       Current.point_size[0] = 10;
       strupr( &Current.FontPath[0] );
    }

    lookahead = NO_TOKEN;

    skipequal();
    match(PATH);
    skipequal();
    match(PATHSPEC);

    advance();

    while( !match(EOI) )
    {
	if( match(BITCACHE) )
	{
	    skipequal();
	    
	    if( match(NUMBER) )
	    {
	    	Current.BitMapCacheSize = atol( yytext )/1024L;
		advance();
	    }
	}
	else if( match(FSMCACHE) )
	{
	    skipequal();
	    
	    if( match(NUMBER) )
	    {
	        if( !skip )
	    	    Current.SpeedoCacheSize = atol( yytext )/1024L;
		advance();
	    }
	    
	    /* In case we have a 'comma'# 
	     * which is used to divide up the fsm_cache internally
	     * BUT, if we don't have the comma#, don't mess us up.
	     */
	    if( match( COMMA ) )
	    {
	        advance();
	        
		if( match( NUMBER ) )
		{
		   if( !skip )
		      Current.speedo_percent = atoi( yytext );
		   advance();
		}	    
	    }
	}
	else if( match(WIDTH) )
	{
	    skipequal();
	    if( match(NUMBER) )
	    {
	        if( !skip )
	           Current.Width = atoi( yytext );
		advance();
	    }
	}
	else
 	    fonts();

    }
    xclose();
    return 0;
}
Exemplo n.º 8
0
bool CFontThumbnail::create(const QString &path, int width, int height, QImage &img)
{
    QString  realPath(path);
    KTempDir *tempDir = 0;

    KFI_DBUG << "Create font thumbnail for:" << path << endl;

    // Is this a appliaction/vnd.kde.fontspackage file? If so, extract 1 scalable font...
    if(Misc::isPackage(path) || "application/zip"==KMimeType::findByFileContent(path)->name())
    {
        KZip zip(path);

        if(zip.open(QIODevice::ReadOnly))
        {
            const KArchiveDirectory *zipDir=zip.directory();

            if(zipDir)
            {
                QStringList fonts(zipDir->entries());

                if(fonts.count())
                {
                    QStringList::ConstIterator it(fonts.begin()),
                                               end(fonts.end());

                    for(; it!=end; ++it)
                    {
                        const KArchiveEntry *entry=zipDir->entry(*it);

                        if(entry && entry->isFile())
                        {
                            delete tempDir;
                            tempDir=new KTempDir(KStandardDirs::locateLocal("tmp", KFI_TMP_DIR_PREFIX));
                            tempDir->setAutoRemove(true);

                            ((KArchiveFile *)entry)->copyTo(tempDir->name());

                            QString mime(KMimeType::findByPath(tempDir->name()+entry->name())->name());

                            if(mime=="application/x-font-ttf" || mime=="application/x-font-otf" ||
                               mime=="application/x-font-type1")
                            {
                                realPath=tempDir->name()+entry->name();
                                break;
                            }
                            else
                                ::unlink(QFile::encodeName(tempDir->name()+entry->name()).data());
                        }
                    }
                }
            }
        }
    }

    QColor bgnd(Qt::black);

    bgnd.setAlpha(0);
    img=itsEngine.draw(realPath, KFI_NO_STYLE_INFO, 0, QApplication::palette().text().color(), bgnd, width, height, true);

    delete tempDir;
    return !img.isNull();
}
Exemplo n.º 9
0
	void MainWindow::updateClearSelectionButton() {
		clearFontSelectionButton->setHidden(fonts()->selectionEmpty());
	}
Exemplo n.º 10
0
	void MainWindow::updateSelectedFontsLabel() {
		showSelectedFontsCheckbox->setVisible(not fonts()->selectionEmpty() or document->font_search_proxy->showingSelected());

		int font_count = fonts()->selectedFontCount();
				selectionLabel->setText(QString("Selection (%1)").arg(font_count));
	}
Exemplo n.º 11
0
void main()
{ 
    RadonFramework::Radon radon;

    auto& screens = RF_Form::Screen::AllScreens();
    RF_Collect::Array<RadonExample::BasicWindow> windows;

    RF_Mem::AutoPointer<RF_Diag::Appender> debuggerOutput(new RF_IO::LogDebuggerOutput);
    RF_IO::Log::AddAppender(debuggerOutput);

    if(RF_SysProf::AMDGPUService::IsAvailable())
    {
        RF_Mem::AutoPointer<RF_Prof::GPUService> gpuService(new RF_SysProf::AMDGPUService("AMD"_rfs));
        gpuService->ObtainGPUs();
        RF_Prof::GPUServiceLocator::Register(gpuService);
    }

    if(RF_SysProf::NvidiaGPUService::IsAvailable())
    {
        RF_Mem::AutoPointer<RF_Prof::GPUService> gpuService(new RF_SysProf::NvidiaGPUService("Nvidia"_rfs));
        gpuService->ObtainGPUs();
        RF_Prof::GPUServiceLocator::Register(gpuService);
    }

    RF_Type::String iso = RF_SysEnv::ActiveLanguage();
    RF_Collect::Array<RF_Text::UnicodeRangeInfo> ranges;
    auto& fontService = RF_Draw::FontServiceLocator::Default();
    fontService.GetUnicodeCharRanges(iso, ranges);
    fontService.EnableCharRangeFilter(ranges);
    fontService.Update();

    RF_Collect::Array<RF_Draw::Image> glyphs;
    RF_Collect::Array<RF_Draw::Path2D> glyphOutlines;
    auto& fonts = fontService.Fonts();
    if(fonts.Count() > 0)
    {
        RF_Collect::Array<RF_Type::UInt32> utf32;
        RF_Text::UnicodeRangeInfo range;
        fontService.GetUnicodeCharRange(fonts(0).Variations(0).SupportedUnicodeSubranges(0), range);
        utf32.Resize(range.End() - range.Start());
        for(RF_Type::Size i = 0; i < utf32.Count(); ++i)
        {
            utf32(i) = range.Start() + i;
        }
        fontService.LoadGlyphs(fonts(0), utf32, glyphOutlines);
        fontService.LoadGlyphs(fonts(0), utf32, glyphs);
    }

    windows.Resize(screens.Count());

    for(RF_Type::Size i = 0; i < screens.Count(); i++)
    {
        windows(i).SetWindowPosition(screens[i].Position());
        RF_Type::UInt32 dpiX = screens[i].DPIX();
        RF_Type::UInt32 dpiY = screens[i].DPIY();
        RF_Geo::Size2D<> windowSize((windows(i).Width()*dpiX) / 96, (windows(i).Height()*dpiY) / 96);
        RF_Geo::Point2D<> dpi;
        dpi.X = dpiX;
        dpi.Y = dpiY;
        windows(i).DPIChanged(dpi);
        windows(i).SetWindowSize(windowSize);
        windows(i).Title(RF_Type::String::Format("X=%ddpi Y=%ddpi"_rfs, dpiX, dpiY));
        windows(i).GetImage().SetImage(glyphs(1));
    }

    auto* app = RF_Form::WindowServiceLocator::Default().Application();
    if (app != nullptr)
    {
        app->ShowConsole(false);
        app->Run(&windows(0));
    }
    
    return;
}
Exemplo n.º 12
0
bool MapnikRenderer::Preprocess( IImporter* importer, QString dir )
{
	QString filename = fileInDirectory( dir, "Mapnik Renderer" );

	try {
		IImporter::BoundingBox box;
		if ( !importer->GetBoundingBox( &box ) )
			return false;
		std::vector< IImporter::RoutingEdge > inputEdges;
		std::vector< IImporter::RoutingNode > inputNodes;
		std::vector< IImporter::RoutingNode > inputPaths;
		if ( m_settings.deleteTiles ) {
			if ( !importer->GetRoutingEdges( &inputEdges ) ) {
				qCritical() << "Mapnik Renderer: failed to read routing edges";
				return false;
			}
			if ( !importer->GetRoutingNodes( &inputNodes ) ) {
				qCritical() << "Mapnik Renderer: failed to read routing nodes";
				return false;
			}
			if ( !importer->GetRoutingEdgePaths( &inputPaths ) ) {
				qCritical() << "Mapnik Renderer: failed to read routing paths";
			}
		}

		Timer time;

		mapnik::datasource_cache::instance().register_datasources( m_settings.plugins.toLatin1().constData() );
		QDir fonts( m_settings.fonts );
		mapnik::projection projection( "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over" );
		mapnik::freetype_engine::register_font( fonts.filePath( "DejaVuSans.ttf" ).toLatin1().constData() );
		mapnik::freetype_engine::register_font( fonts.filePath( "DejaVuSans-Bold.ttf" ).toLatin1().constData() );
		mapnik::freetype_engine::register_font( fonts.filePath( "DejaVuSans-Oblique.ttf" ).toLatin1().constData() );
		mapnik::freetype_engine::register_font( fonts.filePath( "DejaVuSans-BoldOblique.ttf" ).toLatin1().constData() );

		qDebug() << "Mapnik Renderer: initialized mapnik connection:" << time.restart() << "ms";

		int numThreads = omp_get_max_threads();
		qDebug() << "Mapnik Renderer: using" << numThreads << "threads";

		qDebug() << "Mapnik Renderer: x: " << box.min.x << "-" << box.max.x;
		qDebug() << "Mapnik Renderer: y: " << box.min.y << "-" << box.max.y;

		FileStream configData( filename );
		if ( !configData.open( QIODevice::WriteOnly ) )
			return false;

		configData << quint32( m_settings.tileSize ) << quint32( m_settings.zoomLevels.size() );

		long long tilesSkipped = 0;
		long long tiles = 0;
		long long metaTilesRendered = 0;
		long long pngcrushSaved = 0;

		std::vector< ZoomInfo > zoomInfo( m_settings.zoomLevels.size() );
		std::vector< MetaTile > tasks;

		for ( int zoomLevel = 0; zoomLevel < ( int ) m_settings.zoomLevels.size(); zoomLevel++ ) {
			ZoomInfo& info = zoomInfo[zoomLevel];
			int zoom = m_settings.zoomLevels[zoomLevel];

			info.minX = box.min.GetTileX( zoom );
			info.maxX = box.max.GetTileX( zoom ) + 1;
			info.minY = box.min.GetTileY( zoom );
			info.maxY = box.max.GetTileY( zoom ) + 1;

			if ( zoom <= m_settings.fullZoom ) {
				info.minX = info.minY = 0;
				info.maxX = info.maxY = 1 << zoom;
			} else {
				info.minX = std::max( 0 , info.minX - m_settings.tileMargin );
				info.maxX = std::min ( 1 << zoom, info.maxX + m_settings.tileMargin );
				info.minY = std::max( 0, info.minY - m_settings.tileMargin );
				info.maxY = std::min ( 1 << zoom, info.maxY + m_settings.tileMargin );
			}

			tiles += ( info.maxX - info.minX ) * ( info.maxY - info.minY );
			qDebug() << "Mapnik Renderer: [" << zoom << "] x:" << info.minX << "-" << info.maxX << "; y:" << info.minY << "-" << info.maxY;
			configData << quint32( zoom ) << quint32( info.minX ) << quint32( info.maxX ) << quint32( info.minY ) << quint32( info.maxY );

			int numberOfTiles = ( info.maxX - info.minX ) * ( info.maxY - info.minY );
			IndexElement dummyIndex;
			dummyIndex.start = dummyIndex.size = 0;
			info.index.resize( numberOfTiles, dummyIndex );

			std::vector< UnsignedCoordinate > path;
			for ( std::vector< IImporter::RoutingEdge >::const_iterator i = inputEdges.begin(), e = inputEdges.end(); i != e; ++i ) {
				path.push_back( inputNodes[i->source].coordinate );
				for ( int pathID = 0; pathID < i->pathLength; pathID++ )
					path.push_back( inputPaths[pathID + i->pathID].coordinate );
				path.push_back( inputNodes[i->target].coordinate );

				for ( unsigned edge = 0; edge < path.size(); edge++ ) {
					int sourceX = path[edge].GetTileX( zoom );
					int sourceY = path[edge].GetTileY( zoom );
					int targetX = path[edge].GetTileX( zoom );
					int targetY = path[edge].GetTileY( zoom );
					if ( sourceX > targetX )
						std::swap( sourceX, targetX );
					if ( sourceY > targetY )
						std::swap( sourceY, targetY );
					sourceX = std::max( sourceX, info.minX );
					sourceX = std::min( sourceX, info.maxX - 1 );
					sourceY = std::max( sourceY, info.minY );
					sourceY = std::min( sourceY, info.maxY - 1 );
					targetX = std::max( targetX, info.minX );
					targetX = std::min( targetX, info.maxX - 1 );
					targetY = std::max( targetY, info.minY );
					targetY = std::min( targetY, info.maxY - 1 );
					for ( int x = sourceX; x <= targetX; ++x )
						for ( int y = sourceY; y <= targetY; ++y )
							info.index[( x - info.minX ) + ( y - info.minY ) * ( info.maxX - info.minX )].size = 1;
				}

				path.clear();
			}

			info.tilesFile = new QFile( filename + QString( "_%1_tiles" ).arg( zoom ) );
			if ( !openQFile( info.tilesFile, QIODevice::WriteOnly ) )
				return false;

			for ( int x = info.minX; x < info.maxX; x+= m_settings.metaTileSize ) {
				int metaTileSizeX = std::min( m_settings.metaTileSize, info.maxX - x );
				for ( int y = info.minY; y < info.maxY; y+= m_settings.metaTileSize ) {
					int metaTileSizeY = std::min( m_settings.metaTileSize, info.maxY - y );
					MetaTile tile;
					tile.zoom = zoomLevel;
					tile.x = x;
					tile.y = y;
					tile.metaTileSizeX = metaTileSizeX;
					tile.metaTileSizeY = metaTileSizeY;
					tasks.push_back( tile );
				}
			}
		}


#pragma omp parallel
		{
			int threadID = omp_get_thread_num();
			const int metaTileSize = m_settings.metaTileSize * m_settings.tileSize + 2 * m_settings.margin;

			mapnik::Map map;
			mapnik::image_32 image( metaTileSize, metaTileSize );
			QTemporaryFile tempOut;
			QTemporaryFile tempIn;
			mapnik::load_map( map, m_settings.theme.toLocal8Bit().constData() );

#pragma omp for schedule( dynamic )
			for ( int i = 0; i < ( int ) tasks.size(); i++ ) {

				int metaTileSizeX = tasks[i].metaTileSizeX;
				int metaTileSizeY = tasks[i].metaTileSizeY;
				int x = tasks[i].x;
				int y = tasks[i].y;
				int zoomLevel = tasks[i].zoom;
				int zoom = m_settings.zoomLevels[zoomLevel];
				ZoomInfo& info = zoomInfo[zoomLevel];

				map.resize( metaTileSizeX * m_settings.tileSize + 2 * m_settings.margin, metaTileSizeY * m_settings.tileSize + 2 * m_settings.margin );

				ProjectedCoordinate drawTopLeft( x - 1.0 * m_settings.margin / m_settings.tileSize, y - 1.0 * m_settings.margin / m_settings.tileSize, zoom );
				ProjectedCoordinate drawBottomRight( x + metaTileSizeX + 1.0 * m_settings.margin / m_settings.tileSize, y + metaTileSizeY + 1.0 * m_settings.margin / m_settings.tileSize, zoom );
				GPSCoordinate drawTopLeftGPS = drawTopLeft.ToGPSCoordinate();
				GPSCoordinate drawBottomRightGPS = drawBottomRight.ToGPSCoordinate();
				projection.forward( drawTopLeftGPS.longitude, drawBottomRightGPS.latitude );
				projection.forward( drawBottomRightGPS.longitude, drawTopLeftGPS.latitude );
				mapnik::box2d<double> boundingBox( drawTopLeftGPS.longitude, drawTopLeftGPS.latitude, drawBottomRightGPS.longitude, drawBottomRightGPS.latitude );
				map.zoom_to_box( boundingBox );
				mapnik::agg_renderer<mapnik::image_32> renderer( map, image );
				renderer.apply();

				std::string data;
				int skipped = 0;
				int saved = 0;
				for ( int subX = 0; subX < metaTileSizeX; ++subX ) {
					for ( int subY = 0; subY < metaTileSizeY; ++subY ) {
						int indexNumber = ( y + subY - info.minY ) * ( info.maxX - info.minX ) + x + subX - info.minX;
						mapnik::image_view<mapnik::image_data_32> view = image.get_view( subX * m_settings.tileSize + m_settings.margin, subY * m_settings.tileSize + m_settings.margin, m_settings.tileSize, m_settings.tileSize );
						std::string result;
						if ( !m_settings.deleteTiles || info.index[( x + subX - info.minX ) + ( y + subY - info.minY ) * ( info.maxX - info.minX )].size == 1 ) {
							if ( m_settings.reduceColors )
								result = mapnik::save_to_string( view, "png256" );
							else
								result = mapnik::save_to_string( view, "png" );

							if ( m_settings.pngcrush ) {
								tempOut.open();
								tempOut.write( result.data(), result.size() );
								tempOut.flush();
								tempIn.open();
								pclose( popen( ( "pngcrush " + tempOut.fileName() + " " + tempIn.fileName() ).toUtf8().constData(), "r" ) );
								QByteArray buffer = tempIn.readAll();
								tempIn.close();
								tempOut.close();
								if ( buffer.size() != 0 && buffer.size() < ( int ) result.size() ) {
									saved += result.size() - buffer.size();
									result.assign( buffer.constData(), buffer.size() );
								}
							}
						}

						info.index[indexNumber].start = data.size();
						info.index[indexNumber].size = result.size();
						data += result;
					}
				}

				qint64 position;
#pragma omp critical
				{
					position = info.tilesFile->pos();
					info.tilesFile->write( data.data(), data.size() );

					metaTilesRendered++;
					tilesSkipped += skipped;
					pngcrushSaved += saved;
					qDebug() << "Mapnik Renderer: [" << zoom << "], thread" << threadID << ", metatiles:" << metaTilesRendered << "/" << tasks.size();
				}

				for ( int subX = 0; subX < metaTileSizeX; ++subX ) {
					for ( int subY = 0; subY < metaTileSizeY; ++subY ) {
						int indexNumber = ( y + subY - info.minY ) * ( info.maxX - info.minX ) + x + subX - info.minX;
						info.index[indexNumber].start += position;
					}
				}
			}
		}

		for ( int zoomLevel = 0; zoomLevel < ( int ) m_settings.zoomLevels.size(); zoomLevel++ ) {
			const ZoomInfo& info = zoomInfo[zoomLevel];
			int zoom = m_settings.zoomLevels[zoomLevel];
			QFile indexFile( filename + QString( "_%1_index" ).arg( zoom ) );
			if ( !openQFile( &indexFile, QIODevice::WriteOnly ) )
				return false;
			for ( int i = 0; i < ( int ) info.index.size(); i++ ) {
				indexFile.write( ( const char* ) &info.index[i].start, sizeof( info.index[i].start ) );
				indexFile.write( ( const char* ) &info.index[i].size, sizeof( info.index[i].size ) );
			}
			delete info.tilesFile;
		}

		if ( m_settings.deleteTiles )
			qDebug() << "Mapnik Renderer: removed" << tilesSkipped << "tiles";
		if ( m_settings.pngcrush )
			qDebug() << "Mapnik Renderer: PNGcrush saved" << pngcrushSaved / 1024 / 1024 << "MB";

		qDebug() << "Mapnik Renderer: finished:" << time.restart() << "ms";

	} catch ( const mapnik::config_error & ex ) {
		qCritical( "Mapnik Renderer: ### Configuration error: %s", ex.what() );
		return false;
	} catch ( const std::exception & ex ) {
		qCritical( "Mapnik Renderer: ### STD error: %s", ex.what() );
		return false;
	} catch ( ... ) {
		qCritical( "Mapnik Renderer: ### Unknown error" );
		return false;
	}
	return true;
}
Exemplo n.º 13
0
/* parse_extend()
 * ====================================================================
 * Parse the EXTEND.SYS file
 * IN: int skip		0 - Don't skip anything, parse everything.
 *			    Used during a rez change or boot-up
 *			1 - Skip parsing the path. Used during a 
 *			    directory change.
 */
int
parse_extend( int skip )
{
    long len;
    char *txtptr;


    /* Get the Bootup Device */
    Supexec( GetBootDevice );
    drv = BootDevice;
    Drive = BootDevice + 'A';
    epath[0] = Drive;   

    errno = 0;
    xopen( epath );

    /* Check to see if the file 'EXTEND.SYS' exists.
     * If it doesn't, set the path to the root of the bootup device
     * and get the fonts that can be found there.
     */
    if( errno )
    {
        if( !skip )	
        {
           sprintf( Current.FontPath, "%c:", Drive );
           
  	   /* set some defaults here ONLY when we are supposed
  	    * to parse EVERYTHING. This way when we are only 
  	    * switching directories, the current values are 
  	    * NOT affected.
  	    */
	   Current.FSMCacheSize = 100L;	/* Set to 100K */
	   Current.BITCacheSize = 100L;
	   Current.fsm_percent  = 5;	/* Set to 50% */
        }     
/*	get_all_fsm_fonts();*/
	
	
	
	return( errno );
    }
    lookahead = NO_TOKEN;

    /* If we are just interested in the fonts and info stuff,
     * let's skip the path parsing 
     */
    if( skip )
    {
       skipequal();
       match(PATH);
       skipequal();
       match(PATHSPEC);
       goto skip_me;
    }   

       
    /* Check if the PATH line is at the top of the 'EXTEND.SYS' file
     * If its not, we abort
     */   
    if( !match(PATH) )
    {
	/* Error: No Path line at the top of the extend.sys file */
	xclose();	 
        sprintf( Current.FontPath, "%c:", Drive );
	Current.FSMCacheSize = 100L;	/* Set to 100K */
	Current.BITCacheSize = 100L;
	Current.fsm_percent  = 5;	/* Set to 50% */
/*	get_all_fsm_fonts();*/
	return( 1 );
    }

    skipequal();

    if( match(PATHSPEC) )
    {
	strncpy( fsmpath, yytext, yyleng );
	len = yyleng-1;
	if( fsmpath[len] != '\\' ) ++len;
	fsmpath[len] = '\0';
	if( len > 2 )	/* below code fails for items like 'f:'*/
	{
	  if( !stat(fsmpath, &statbuf) )
	      errno = (isdir(&statbuf)) ? 0 : ENOTDIR;
	  if( errno )
	  {
	    /* Error Parsing the path */    
	    xclose();
            sprintf( Current.FontPath, "%c:", Drive );
	    Current.FSMCacheSize = 100L;	/* Set to 100K */
	    Current.BITCacheSize = 100L;
	    Current.fsm_percent  = 5;	/* Set to 50% */
/*	    get_all_fsm_fonts();*/
	    return( errno );
	  }
	}  
    }
    else
    {
        /* Error parsing the word 'PATHSPEC' */
	xclose();
        sprintf( Current.FontPath, "%c:", Drive );
	Current.FSMCacheSize = 100L;	/* Set to 100K */
	Current.BITCacheSize = 100L;
	Current.fsm_percent  = 5;	/* Set to 50% */
/*	get_all_fsm_fonts();*/
	return( 1 );
    }
skip_me:    
    advance();
    
    if( !skip )
        strcpy( Current.FontPath, fsmpath );
    else
        strcpy( fsmpath, Current.FontPath );
    txtptr = Current.FontPath;
    txtptr = strupr( txtptr );
#if 0
    get_all_fsm_fonts();
#endif
    while( !match(EOI) )
    {
	if( match(BITCACHE) )
	{
	    skipequal();
	    if( match(NUMBER) )
	    {
	    	Current.BITCacheSize = atol( yytext )/1024L;
		advance();
	    }
	    else
	    	Current.BITCacheSize = 0L;
	}
	else if( match(FSMCACHE) )
	{
	    skipequal();
	    if( match(NUMBER) )
	    {
	    	Current.FSMCacheSize = atol( yytext )/1024L;
		advance();
	    }
	    else
	    	Current.FSMCacheSize = 0L;
	    
	    /* In case we have a 'comma'# 
	     * which is used to divide up the fsm_cache internally
	     * BUT, if we don't have the comma#, don't mess us up.
	     */
	    if( match( COMMA ) )
	    {
	        advance();
	        
		if( match( NUMBER ) )
		{
		   /* convert the number here to integer*/
		   Current.fsm_percent = atoi( yytext );
		   advance();
		}	    
	    }
	    else
	       Current.fsm_percent = 5;	/* 50% */
	}
	else if( match(WIDTH) )
	{
	    skipequal();
	    if( match(NUMBER) )
	    {
	        Current.Width = atoi( yytext );
		advance();
	    }
	    else
	    	Current.Width = 0;
	}
	else
 	    fonts();

    }
    xclose();
    return 0;
}