Beispiel #1
0
void Serializer::updateGradientColors(const ColorList& colors)
{
	VColorStop* grStop;
	uint itemsCount = m_Doc.Items->count();
	for (uint c=0; c < itemsCount; ++c)
	{
		PageItem *ite = m_Doc.Items->at(c);
		QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
		for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->stroke_gradient.colorStops();
		for (uint cst = 0; cst < ite->stroke_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->mask_gradient.colorStops();
		for (uint cst = 0; cst < ite->mask_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
	}
	uint masterItemsCount =  m_Doc.MasterItems.count();
	for (uint c=0; c < masterItemsCount; ++c)
	{
		PageItem *ite = m_Doc.MasterItems.at(c);
		QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
		for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->stroke_gradient.colorStops();
		for (uint cst = 0; cst < ite->stroke_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->mask_gradient.colorStops();
		for (uint cst = 0; cst < ite->mask_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
	}
	uint frameItemsCount = m_Doc.FrameItems.count();
	for (uint c=0; c < frameItemsCount; ++c)
	{
		PageItem *ite = m_Doc.FrameItems.at(c);
		QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
		for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->stroke_gradient.colorStops();
		for (uint cst = 0; cst < ite->stroke_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
		cstops = ite->mask_gradient.colorStops();
		for (uint cst = 0; cst < ite->mask_gradient.Stops(); ++cst)
		{
			grStop = cstops.at(cst);
			if (colors.contains(grStop->name))
				grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
		}
	}
	QStringList patterns =m_Doc.docPatterns.keys();
	for (int c = 0; c < patterns.count(); ++c)
	{
		ScPattern& pa = m_Doc.docPatterns[patterns[c]];
		for (int o = 0; o < pa.items.count(); o++)
		{
			PageItem *ite = pa.items.at(o);
			QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
			for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
			{
				grStop = cstops.at(cst);
				if (colors.contains(grStop->name))
					grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
			}
			cstops = ite->stroke_gradient.colorStops();
			for (uint cst = 0; cst < ite->stroke_gradient.Stops(); ++cst)
			{
				grStop = cstops.at(cst);
				if (colors.contains(grStop->name))
					grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
			}
			cstops = ite->mask_gradient.colorStops();
			for (uint cst = 0; cst < ite->mask_gradient.Stops(); ++cst)
			{
				grStop = cstops.at(cst);
				if (colors.contains(grStop->name))
					grStop->color = SetColor(&m_Doc, grStop->name, grStop->shade);
			}
		}
	}
}
Beispiel #2
0
void Serializer::serializeObjects(const Selection& selection, SaxHandler& outputhandler)
{
	Xml_attr attr;
	UniqueID handler( & outputhandler );
	handler.beginDoc();
	handler.begin("SCRIBUSFRAGMENT", attr);
	ScribusDoc* doc = selection.itemAt(0)->doc();
	
	
	QMap<QString,int>::Iterator itf;
	for (itf = doc->UsedFonts.begin(); itf != doc->UsedFonts.end(); ++itf)
	{
		attr["name"] = itf.key();
		handler.beginEnd("font", attr);
	}
	
	ColorList usedColors;
	doc->getUsedColors(usedColors, false);
	ColorList::Iterator itc;
	for (itc = usedColors.begin(); itc != usedColors.end(); ++itc)
	{
		Xml_attr cattr;
		cattr["name"] = itc.key();
		if (doc->PageColors[itc.key()].getColorModel() == colorModelRGB)
			cattr["RGB"] = doc->PageColors[itc.key()].nameRGB();
		else
			cattr["CMYK"] = doc->PageColors[itc.key()].nameCMYK();
		cattr["Spot"] = toXMLString(doc->PageColors[itc.key()].isSpotColor());
		cattr["Register"] = toXMLString(doc->PageColors[itc.key()].isRegistrationColor());
		handler.beginEnd("color", cattr);
	}
	
	ResourceCollection lists;
	for (int i=0; i < doc->Items->count(); ++i)
		doc->Items->at(i)->getNamedResources(lists);
	
	QList<QString>::Iterator it;
	QList<QString> names = lists.styleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->paragraphStyles().get(*it).saxx(handler);

	names = lists.charStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->charStyles().get(*it).saxx(handler);
	
	names = lists.lineStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
	{
		Xml_attr multiattr;
		multiattr["Name"] = *it;
		handler.begin("MultiLine", multiattr);		
		multiLine ml = doc->MLineStyles[*it];
		
		multiLine::Iterator itMU2;
		for (itMU2 = ml.begin(); itMU2 != ml.end(); ++itMU2)
		{
			Xml_attr lineattr;
			lineattr["Color"] = (*itMU2).Color;
			lineattr["Shade"] = toXMLString((*itMU2).Shade);
			lineattr["Dash"] = toXMLString((*itMU2).Dash);
			lineattr["LineEnd"] = toXMLString((*itMU2).LineEnd);
			lineattr["LineJoin"] = toXMLString((*itMU2).LineJoin);
			lineattr["Width"] = toXMLString((*itMU2).Width);
			handler.beginEnd("SubLine", lineattr);
		}
		handler.end("MultiLine");
	}

	/*	names = lists.patterns();
	for (it = names.begin(); it != names.end(); ++it)
		doc->patterns[*it].saxx(handler);
*/
/*
	QStringList patterns = doc->getUsedPatternsSelection((Selection*)&selection);
	for (int c = 0; c < patterns.count(); ++c)
	{
		ScPattern& pa = doc->docPatterns[patterns[c]];
		Xml_attr cattr;
		cattr["Name"] = patterns[c];
		cattr["scaleX"] = toXMLString(pa.scaleX);
		cattr["scaleY"] = toXMLString(pa.scaleY);
		cattr["width"] = toXMLString(pa.width);
		cattr["height"] = toXMLString(pa.height);
		cattr["xoffset"] = toXMLString(pa.xoffset);
		cattr["yoffset"] = toXMLString(pa.yoffset);
		handler.begin("Pattern", cattr);
		for (int o = 0; o < pa.items.count(); o++)
		{
			pa.items.at(o)->saxx(handler);
		}
		handler.end("Pattern");
	}
*/
	for (int i=0; i < doc->Items->count(); ++i)
	{
		int k = selection.findItem(doc->Items->at(i));
		if (k >=0)
			doc->Items->at(i)->saxx(handler);
	}

	handler.end("SCRIBUSFRAGMENT");
	handler.endDoc();
}
Beispiel #3
0
int main(void)
{
    ALLEGRO_COLOR background, active, inactive, info;
    old_dialog = NULL;
    cur_dialog = NULL;
    bool redraw = false;
    bool close_log = false;
    bool message_log = true;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    //open_log();
    log_printf("Starting up log window.\n");

    al_init_image_addon();
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();

    background = al_map_rgb(0,0,98);
    active = al_color_name("white");
    inactive = al_color_name("gray");
    info = al_color_name("red");

    user_config.save_values();
    user_config.load_file();
    user_config.retrieve_values();

    if((!user_config.map_path.empty()) && user_config.map_autoload)
    {
        populate_filenames(user_config.map_path, &path_list);
        load_bitmaps(&path_list, &map_list);
    }

    al_install_mouse();
    al_install_keyboard();

    al_set_new_display_flags(ALLEGRO_RESIZABLE);
    display = al_create_display(user_config.res_x, user_config.res_y);
    if (!display) {
        log_printf("failure.\n");
        abort_example("Error creating display\n");
        return 1;
    }
    ALLEGRO_BITMAP * isoicon = al_load_bitmap("isoworld/isoWorld.png");
    if(isoicon) {
        al_set_display_icon(display, isoicon);
    }
    al_set_window_title(display, "IsoWorld");

    log_printf("success.\n");

    log_printf("Loading font '%s'...", "isoworld/DejaVuSans.ttf");
    user_config.font = al_load_font("isoworld/DejaVuSans.ttf", 14, 0);
    if (!user_config.font) {
        log_printf("failure.\n");
        abort_example("Error loading isoworld/DejaVuSans.ttf\n");
        return 1;
    }
    log_printf("success.\n");

    timer = al_create_timer(1.0 / 30);
    network_timer = al_create_timer(1.0);
    log_printf("Starting main loop.\n");
    allegro_queue = al_create_event_queue();
    al_register_event_source(allegro_queue, al_get_keyboard_event_source());
    al_register_event_source(allegro_queue, al_get_mouse_event_source());
    al_register_event_source(allegro_queue, al_get_display_event_source(display));
    al_register_event_source(allegro_queue, al_get_timer_event_source(timer));
    al_register_event_source(allegro_queue, al_get_timer_event_source(network_timer));
    if (textlog) {
        al_register_event_source(allegro_queue, al_get_native_text_log_event_source(
            textlog));
    }
    al_start_timer(timer);
    al_start_timer(network_timer);

    initializeAgui();
    add_widgets();

    MapSection test_map;

    test_map.set_size(user_config.map_width, user_config.map_height);

    minimap.reload();

    test_map.load_tilesets("isoworld/tilesets.ini");
    main_screen->UpdateTilesetList(&test_map);

    test_map.board_center_x = 0;
    test_map.board_top_y = 0;

    load_detailed_tiles(path_list.elevation_map, &test_map);

    int selection = 0;

    bool mapmove = 0;
    bool rightmove = 0;
    int mousemove_start_x = 0;
    int mousemove_start_y = 0;
    int mapmove_start_x = 0;
    int mapmove_start_y = 0;

    ALLEGRO_COLOR unselected = al_map_rgb(255,255,255);
    ALLEGRO_COLOR selected = al_map_rgb(128,128,128);

    ALLEGRO_KEYBOARD_STATE keys;
    while (1) {
        float h = al_get_display_height(display);
        float w = al_get_display_width(display);
        ALLEGRO_EVENT event;
        al_wait_for_event(allegro_queue, &event);

        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE && !cur_dialog)
            break;

        if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
            al_get_keyboard_state(&keys);
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE && !cur_dialog)
                break;
            else if (event.keyboard.keycode == ALLEGRO_KEY_UP && !cur_dialog)
            {
                if(al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
                    user_config.map_y-=10;
                else
                    user_config.map_y--;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN && !cur_dialog)
            {
                if(al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
                    user_config.map_y+=10;
                else
                    user_config.map_y++;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_RIGHT && !cur_dialog)
            {
                if(al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
                    user_config.map_x+=10;
                else
                    user_config.map_x++;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_LEFT && !cur_dialog)
            {
                if(al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
                    user_config.map_x-=10;
                else
                    user_config.map_x--;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_F5 && !cur_dialog)
            {
                saveScreenshot();
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_G && !cur_dialog)
            {
                user_config.showgrid = !user_config.showgrid;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_Q && !cur_dialog)
            {
                if(user_config.ray_distance > 1)
                    user_config.ray_distance --;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_W && !cur_dialog)
            {
                user_config.ray_distance++;
                continue;
            }
            else if (event.keyboard.keycode == ALLEGRO_KEY_D && !cur_dialog)
            {
                user_config.debugmode = !user_config.debugmode;
                continue;
            }
        }

        /* When a mouse button is pressed, and no native dialog is
        * shown already, we show a new one.
        */
        if(event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
        {
            mapmove = false;
            rightmove = false;
        }
        if(event.type == ALLEGRO_EVENT_MOUSE_AXES)
        {
            if(mapmove)
            {
                if ((event.mouse.x >= w - user_config.minimap_size) && (event.mouse.y >= user_config.minimap_size))
                {
                    mapmove = true;
                    int relx = event.mouse.x - w + user_config.minimap_size -1;
                    int rely = event.mouse.y - h + user_config.minimap_size -1;
                    user_config.map_x = (float)al_get_bitmap_width(map_list.biome_map)/user_config.minimap_size * relx - user_config.map_width/2;
                    user_config.map_y = (float)al_get_bitmap_height(map_list.biome_map)/user_config.minimap_size * rely - user_config.map_height/2;
                }
                else
                    mapmove = false;
            }
            if(rightmove)
            {
                user_config.map_x = mapmove_start_x - ((event.mouse.x - mousemove_start_x) / test_map.tileset_list[test_map.current_tileset].tile_width) - ((event.mouse.y - mousemove_start_y) / test_map.tileset_list[test_map.current_tileset].tile_height);
                user_config.map_y = mapmove_start_y + ((event.mouse.x - mousemove_start_x) / test_map.tileset_list[test_map.current_tileset].tile_width) - ((event.mouse.y - mousemove_start_y) / test_map.tileset_list[test_map.current_tileset].tile_height);
            }
        }
        if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
            //log_printf("Mouse clicked at %d,%d.\n", event.mouse.x, event.mouse.y);
            if(event.mouse.button == 2)
            {
                rightmove = true;
                mousemove_start_x = event.mouse.x;
                mousemove_start_y = event.mouse.y;
                mapmove_start_x = user_config.map_x;
                mapmove_start_y = user_config.map_y;
            }
            else if ((event.mouse.x >= w - user_config.minimap_size) && (event.mouse.y >= user_config.minimap_size))
            {
                mapmove = true;
                int relx = event.mouse.x - w + user_config.minimap_size -1;
                int rely = event.mouse.y - h + user_config.minimap_size -1;
                user_config.map_x = (float)al_get_bitmap_width(map_list.biome_map)/user_config.minimap_size * relx - user_config.map_width/2;
                user_config.map_y = (float)al_get_bitmap_height(map_list.biome_map)/user_config.minimap_size * rely - user_config.map_height/2;
            }
            else if (event.mouse.y > 30) {
                if (event.mouse.y > h - 30) {
                    message_log = !message_log;
                    if (message_log) {
                        textlog = al_open_native_text_log("Log", 0);
                        if (textlog) {
                            al_register_event_source(allegro_queue,
                                al_get_native_text_log_event_source(textlog));
                        }
                    }
                    else {
                        close_log = true;
                    }
                }
            }
        }
        /* We receive this event from the other thread when the dialog is
        * closed.
        */
        if (event.type == ASYNC_DIALOG_EVENT1) {
            al_unregister_event_source(allegro_queue, &cur_dialog->event_source);

            /* If files were selected, we replace the old files list.
            * Otherwise the dialog was cancelled, and we keep the old results.
            */
            if (al_get_native_file_dialog_count(cur_dialog->file_dialog) > 0) {
                if (old_dialog)
                    stop_async_dialog(old_dialog);
                old_dialog = cur_dialog;
            }
            else {
                stop_async_dialog(cur_dialog);
            }
            cur_dialog = NULL;
        }

        if (event.type == ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE) {
            close_log = true;
        }

        if (event.type == ALLEGRO_EVENT_TIMER) {
            if(event.timer.source == timer)
                redraw = true;
            else if(event.timer.source == network_timer) {
                if(connection_state) {
                    al_stop_timer(network_timer); //wait at least a second between the end of load and the start of the next, not between the start and start.
                    connection_state->net_request.set_save_folder(current_save);
                    if(!color_list.has_names){
                        if(connection_state->MaterialInfoCall(&connection_state->net_request, &connection_state->net_material_names) == DFHack::command_result::CR_OK) {
                            if(connection_state->net_material_names.available()) {
                                color_list.import_names(&connection_state->net_material_names);
                                if(!color_list.has_colors) {
                                    color_list.import_colors("isoworld/material_colors.ini");
                                }
                            }
                        }
                        else {
                            delete connection_state;
                            connection_state = NULL;
                            goto EXIT_LOOP;
                        }
                    }
                    if(connection_state->EmbarkInfoCall(&connection_state->net_request, &connection_state->net_reply) == DFHack::command_result::CR_OK) {
                        if(connection_state->net_reply.available()) {
                            if(center_on_loaded_map) {
                                user_config.map_x = connection_state->net_reply.region_x() + (connection_state->net_reply.region_size_x() / 2) - (user_config.map_width / 2);
                                user_config.map_y = connection_state->net_reply.region_y() + (connection_state->net_reply.region_size_y() / 2) - (user_config.map_height / 2);
                            }
                            for(int yy = 0; yy < connection_state->net_reply.region_size_y(); yy++) {
                                for(int xx = 0; xx < connection_state->net_reply.region_size_x(); xx++) {
                                    if(!test_map.query_tile(&connection_state->net_reply, xx, yy))
                                        continue;
                                    connection_state->net_tile_request.set_want_x(xx);
                                    connection_state->net_tile_request.set_want_y(yy);
                                    if(connection_state->EmbarkTileCall(&connection_state->net_tile_request, &connection_state->net_embark_tile) == DFHack::command_result::CR_OK) {
                                        if(!connection_state->net_embark_tile.is_valid())
                                            continue;
                                        test_map.make_tile(&connection_state->net_embark_tile, &connection_state->net_reply);
                                        goto EXIT_LOOP;
                                    }
                                    else {
                                        delete connection_state;
                                        connection_state = NULL;
                                        goto EXIT_LOOP;
                                    }
                                }
                            }
                        }
                    }
                    else {
                        delete connection_state;
                        connection_state = NULL;
                        goto EXIT_LOOP;
                    }
EXIT_LOOP: ;
                    al_start_timer(network_timer);
                }
            }
        }
        if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
            al_acknowledge_resize(event.display.source);
            user_config.res_x = al_get_display_width(display);
            user_config.res_y = al_get_display_height(display);
            //Resize Agui
            gui->resizeToDisplay();
            redraw = true;
        }
        if (redraw && al_is_event_queue_empty(allegro_queue)) {
            float x = al_get_display_width(display) / 2;
            float y = 0;
            redraw = false;
            al_clear_to_color(background);
            al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
            if (old_dialog)
            {
                if(old_dialog->newimages)
                {
                    show_files_list(old_dialog->file_dialog, user_config.font, info);
                    old_dialog->newimages = 0;
                    for(int i=0;i<test_map.tileset_list.size();i++){
                        delete test_map.tileset_list[test_map.current_tileset].rendered_map;
                        test_map.tileset_list[test_map.current_tileset].rendered_map = NULL;
                    }
                    load_detailed_tiles(path_list.elevation_map, &test_map);
                }
            }
            test_map.propogate_tiles(&map_list);
            test_map.draw(al_get_display_width(display) / 2, (al_get_display_height(display) / 2) + user_config.map_shift);
            minimap.draw();
            if(user_config.debugmode)
            {
                test_map.draw_debug_info();
                al_draw_textf(user_config.font, cur_dialog ? inactive : active, 0, y, ALLEGRO_ALIGN_LEFT, "Drawtime: %dms", test_map.draw_time);
                al_draw_textf(user_config.font, cur_dialog ? inactive : active, 0, y + al_get_font_line_height(user_config.font), ALLEGRO_ALIGN_LEFT, "Load Time: %dms", test_map.load_time);
                al_draw_textf(user_config.font, cur_dialog ? inactive : active, 0, y + al_get_font_line_height(user_config.font)*2, ALLEGRO_ALIGN_LEFT, "Fetch Time: %dms", test_map.tile_fetch_time);
            }
            gui->logic();
            render_gui();
            al_flip_display();
        }

        if (close_log && textlog) {
            close_log = false;
            message_log = false;
            al_unregister_event_source(allegro_queue,
                al_get_native_text_log_event_source(textlog));
            al_close_native_text_log(textlog);
            textlog = NULL;
        }


        //Let Agui process the event last, because f**k Agui
        inputHandler->processEvent(event);

    }

    log_printf("Exiting.\n");
    if(connection_state) {
        delete connection_state;
        connection_state = NULL;
    }

    imagelist.unload_bitmaps();

    user_config.save_values();
    user_config.save_file();

    al_destroy_event_queue(allegro_queue);

    stop_async_dialog(old_dialog);
    stop_async_dialog(cur_dialog);

    return 0;
}
Beispiel #4
0
bool importColorsFromFile(QString fileName, ColorList &EditColors, QHash<QString, VGradient> *dialogGradients, bool merge)
{
	if (fileName.isEmpty())
		return false;
	int oldCount = EditColors.count();

	QFileInfo fi = QFileInfo(fileName);
	QString ext = fi.suffix().toLower();
	if (extensionIndicatesEPSorPS(ext))
	{
		PaletteLoader_PS psPalLoader;
		psPalLoader.setupTargets(&EditColors, dialogGradients);
		return psPalLoader.importFile(fileName, merge);
	}
	else
	{
		QStringList allFormatsV = LoadSavePlugin::getExtensionsForColors();
		if (allFormatsV.contains(ext))
		{
			FileLoader fl(fileName);
			int testResult = fl.testFile();
			if (testResult != -1)
			{
				ColorList LColors;
				if (fl.readColors(LColors))
				{
					ColorList::Iterator it;
					for (it = LColors.begin(); it != LColors.end(); ++it)
					{
						EditColors.tryAddColor(it.key(), it.value());
					}
					return (EditColors.count() != oldCount);
				}
			}
		}
		if (ext == "acb")			// Adobe color book format
		{
			PaletteLoader_Adobe_acb adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}

			PaletteLoader_Autocad_acb autocadPalLoder;
			if (autocadPalLoder.isFileSupported(fileName))
			{
				autocadPalLoder.setupTargets(&EditColors, dialogGradients);
				return autocadPalLoder.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "aco")			// Adobe color swatch format
		{
			PaletteLoader_Adobe_aco adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "ase")			// Adobe swatch exchange format
		{
			PaletteLoader_Adobe_ase adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "cxf")			// Adobe swatch exchange format
		{
			PaletteLoader_CxF cxfLoader;
			if (cxfLoader.isFileSupported(fileName))
			{
				cxfLoader.setupTargets(&EditColors, dialogGradients);
				return cxfLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "skp")			// Sk1 palette
		{
			PaletteLoader_sK1 sk1PalLoader;
			if (sk1PalLoader.isFileSupported(fileName))
			{
				sk1PalLoader.setupTargets(&EditColors, dialogGradients);
				return sk1PalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "sbz")
		{
			PaletteLoader_Swatchbook swatchbookLoader;
			if (swatchbookLoader.isFileSupported(fileName))
			{
				swatchbookLoader.setupTargets(&EditColors, dialogGradients);
				return swatchbookLoader.importFile(fileName, merge);
			}
			return false;
		}
		else							// try for OpenOffice, Viva and our own format
		{
			QFile fiC(fileName);
			if (fiC.open(QIODevice::ReadOnly))
			{
				QString ColorEn, Cname;
				int Rval, Gval, Bval, Kval;
				ScTextStream tsC(&fiC);
				ColorEn = tsC.readLine();
				bool cus = false;
				if (ColorEn.contains("OpenOffice"))
					cus = true;
				if ((ColorEn.startsWith("<?xml version=")) || (ColorEn.contains("VivaColors")))
				{
					QByteArray docBytes("");
					loadRawText(fileName, docBytes);
					QString docText("");
					docText = QString::fromUtf8(docBytes);
					QDomDocument docu("scridoc");
					docu.setContent(docText);
					ScColor lf = ScColor();
					QDomElement elem = docu.documentElement();
					QString dTag = "";
					dTag = elem.tagName();
					QString nameMask = "%1";
					nameMask = elem.attribute("mask", "%1");
					QDomNode PAGE = elem.firstChild();
					while (!PAGE.isNull())
					{
						QDomElement pg = PAGE.toElement();
						if (pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
						{
							if (pg.hasAttribute("SPACE"))
							{
								QString space = pg.attribute("SPACE");
								if (space == "CMYK")
								{
									double c = pg.attribute("C", "0").toDouble() / 100.0;
									double m = pg.attribute("M", "0").toDouble() / 100.0;
									double y = pg.attribute("Y", "0").toDouble() / 100.0;
									double k = pg.attribute("K", "0").toDouble() / 100.0;
									lf.setCmykColorF(c, m, y, k);
								}
								else if (space == "RGB")
								{
									double r = pg.attribute("R", "0").toDouble() / 255.0;
									double g = pg.attribute("G", "0").toDouble() / 255.0;
									double b = pg.attribute("B", "0").toDouble() / 255.0;
									lf.setRgbColorF(r, g, b);
								}
								else if (space == "Lab")
								{
									double L = pg.attribute("L", "0").toDouble();
									double a = pg.attribute("A", "0").toDouble();
									double b = pg.attribute("B", "0").toDouble();
									lf.setLabColor(L, a, b);
								}
							}
							else if (pg.hasAttribute("CMYK"))
								lf.setNamedColor(pg.attribute("CMYK"));
							else if (pg.hasAttribute("RGB"))
								lf.fromQColor(QColor(pg.attribute("RGB")));
							else
							{
								double L = pg.attribute("L", "0").toDouble();
								double a = pg.attribute("A", "0").toDouble();
								double b = pg.attribute("B", "0").toDouble();
								lf.setLabColor(L, a, b);
							}
							if (pg.hasAttribute("Spot"))
								lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
							else
								lf.setSpotColor(false);
							if (pg.hasAttribute("Register"))
								lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
							else
								lf.setRegistrationColor(false);
							EditColors.tryAddColor(pg.attribute("NAME"), lf);
						}
						else if (pg.tagName() == "Gradient")
						{
							if (dialogGradients != NULL)
							{
								VGradient gra = VGradient(VGradient::linear);
								gra.clearStops();
								QDomNode grad = pg.firstChild();
								while (!grad.isNull())
								{
									QDomElement stop = grad.toElement();
									QString name = stop.attribute("NAME");
									double ramp  = ScCLocale::toDoubleC(stop.attribute("RAMP"), 0.0);
									int shade    = stop.attribute("SHADE", "100").toInt();
									double opa   = ScCLocale::toDoubleC(stop.attribute("TRANS"), 1.0);
									QColor color;
									if (name == CommonStrings::None)
										color = QColor(255, 255, 255, 0);
									else
									{
										const ScColor& col = EditColors[name];
										color = ScColorEngine::getShadeColorProof(col, NULL, shade);
									}
									gra.addStop(color, ramp, 0.5, opa, name, shade);
									grad = grad.nextSibling();
								}
								if ((!dialogGradients->contains(pg.attribute("Name"))) || (merge))
									dialogGradients->insert(pg.attribute("Name"), gra);
								else
								{
									QString tmp;
									QString name = pg.attribute("Name");
									name += "("+tmp.setNum(dialogGradients->count())+")";
									dialogGradients->insert(name, gra);
								}
							}
						}
						else if (pg.tagName()=="draw:color" && pg.attribute("draw:name")!=CommonStrings::None)
						{
							if (pg.hasAttribute("draw:color"))
								lf.setNamedColor(pg.attribute("draw:color"));
							lf.setSpotColor(false);
							lf.setRegistrationColor(false);
							QString nam = pg.attribute("draw:name");
							if (!nam.isEmpty())
								EditColors.tryAddColor(nam, lf);
						}
						else if (dTag == "VivaColors")
						{
							int cVal = 0;
							int mVal = 0;
							int yVal = 0;
							int kVal = 0;
							QString nam = nameMask.arg(pg.attribute("name"));
							if (pg.attribute("type") == "cmyk")
							{
								QDomNode colNode = pg.firstChild();
								while (!colNode.isNull())
								{
									QDomElement colVal = colNode.toElement();
									if (colVal.tagName() == "cyan")
										cVal = colVal.text().toInt();
									if (colVal.tagName() == "magenta")
										mVal = colVal.text().toInt();
									if (colVal.tagName() == "yellow")
										yVal = colVal.text().toInt();
									if (colVal.tagName() == "key")
										kVal = colVal.text().toInt();
									colNode = colNode.nextSibling();
								}
								lf.setColorF(cVal / 100.0, mVal / 100.0, yVal / 100.0, kVal / 100.0);
								lf.setSpotColor(false);
								lf.setRegistrationColor(false);
								if (!nam.isEmpty())
									EditColors.tryAddColor(nam, lf);
							}
							else if (pg.attribute("type") == "rgb")
							{
								QDomNode colNode = pg.firstChild();
								while (!colNode.isNull())
								{
									QDomElement colVal = colNode.toElement();
									if (colVal.tagName() == "red")
										cVal = colVal.text().toInt();
									if (colVal.tagName() == "green")
										mVal = colVal.text().toInt();
									if (colVal.tagName() == "blue")
										yVal = colVal.text().toInt();
									colNode = colNode.nextSibling();
								}
								lf.setRgbColor(cVal, mVal, yVal);
								lf.setSpotColor(false);
								lf.setRegistrationColor(false);
								if (!nam.isEmpty())
									EditColors.tryAddColor(nam, lf);
							}
						}
						PAGE=PAGE.nextSibling();
					}
				}
				else
				{
					QString paletteName = "";
					QString dummy;
					if (ColorEn.startsWith("GIMP Palette"))
					{
						ColorEn = tsC.readLine();
						ScTextStream CoE(&ColorEn, QIODevice::ReadOnly);
						CoE >> dummy >> paletteName;
					}
					while (!tsC.atEnd())
					{
						ScColor tmp;
						ColorEn = tsC.readLine();
						if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
							continue;
						ScTextStream CoE(&ColorEn, QIODevice::ReadOnly);
						CoE >> Rval;
						CoE >> Gval;
						CoE >> Bval;
						if (cus)
						{
							CoE >> Kval;
							Cname = CoE.readAll().trimmed();
							tmp.setColor(Rval, Gval, Bval, Kval);
						}
						else
						{
							Cname = CoE.readAll().trimmed();
							tmp.setRgbColor(Rval, Gval, Bval);
						}
						if (Cname == "Untitled")
							Cname = "";
						if (Cname.length() == 0)
						{
							if (!cus)
								Cname = paletteName + QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
							else
								Cname = paletteName + QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
							Cname.replace(" ","0");
						}
						EditColors.tryAddColor(Cname, tmp);
					}
				}
				fiC.close();
			}
bool importColorsFromFile(QString fileName, ColorList &EditColors)
{
    int oldCount = EditColors.count();
    if (!fileName.isEmpty())
    {
        QFileInfo fi = QFileInfo(fileName);
        QString ext = fi.suffix().toLower();
        if (extensionIndicatesEPSorPS(ext) || (ext == "ai"))
        {
            QString tmp, tmp2, FarNam;
            double c, m, y, k;
            ScColor cc;
            QFile f(fileName);
            if (f.open(QIODevice::ReadOnly))
            {
                bool isAtend = false;
                QDataStream ts(&f);
                while (!ts.atEnd())
                {
                    tmp = readLinefromDataStream(ts);
                    if ((tmp.startsWith("%%CMYKCustomColor")) || (tmp.startsWith("%%CMYKProcessColor")))
                    {
                        if (tmp.contains("(atend)"))
                            isAtend = true;
                        else
                        {
                            if (tmp.startsWith("%%CMYKCustomColor"))
                                tmp = tmp.remove(0,18);
                            else if (tmp.startsWith("%%CMYKProcessColor"))
                                tmp = tmp.remove(0,19);
                            ScTextStream ts2(&tmp, QIODevice::ReadOnly);
                            ts2 >> c >> m >> y >> k;
                            FarNam = ts2.readAll();
                            FarNam = FarNam.trimmed();
                            FarNam = FarNam.remove(0,1);
                            FarNam = FarNam.remove(FarNam.length()-1,1);
                            FarNam = FarNam.simplified();
                            cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
                            cc.setSpotColor(true);
                            if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
                                EditColors.insert(FarNam, cc);
                            while (!ts.atEnd())
                            {
                                quint64 oldPos = ts.device()->pos();
                                tmp = readLinefromDataStream(ts);
                                if (!tmp.startsWith("%%+"))
                                {
                                    ts.device()->seek(oldPos);
                                    break;
                                }
                                tmp = tmp.remove(0,3);
                                ScTextStream ts2(&tmp, QIODevice::ReadOnly);
                                ts2 >> c >> m >> y >> k;
                                FarNam = ts2.readAll();
                                FarNam = FarNam.trimmed();
                                FarNam = FarNam.remove(0,1);
                                FarNam = FarNam.remove(FarNam.length()-1,1);
                                FarNam = FarNam.simplified();
                                cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
                                cc.setSpotColor(true);
                                if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
                                    EditColors.insert(FarNam, cc);
                            }
                        }
                    }
                    if (tmp.startsWith("%%RGBCustomColor"))
                    {
                        if (tmp.contains("(atend)"))
                            isAtend = true;
                        else
                        {
                            tmp = tmp.remove(0,17);
                            ScTextStream ts2(&tmp, QIODevice::ReadOnly);
                            ts2 >> c >> m >> y;
                            FarNam = ts2.readAll();
                            FarNam = FarNam.trimmed();
                            FarNam = FarNam.remove(0,1);
                            FarNam = FarNam.remove(FarNam.length()-1,1);
                            FarNam = FarNam.simplified();
                            cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y));
                            if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
                                EditColors.insert(FarNam, cc);
                            while (!ts.atEnd())
                            {
                                quint64 oldPos = ts.device()->pos();
                                tmp = readLinefromDataStream(ts);
                                if (!tmp.startsWith("%%+"))
                                {
                                    ts.device()->seek(oldPos);
                                    break;
                                }
                                tmp = tmp.remove(0,3);
                                ScTextStream ts2(&tmp, QIODevice::ReadOnly);
                                ts2 >> c >> m >> y;
                                FarNam = ts2.readAll();
                                FarNam = FarNam.trimmed();
                                FarNam = FarNam.remove(0,1);
                                FarNam = FarNam.remove(FarNam.length()-1,1);
                                FarNam = FarNam.simplified();
                                cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y));
                                if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
                                    EditColors.insert(FarNam, cc);
                            }
                        }
                    }
                    if (tmp.startsWith("%%EndComments"))
                    {
                        if (ext == "ai")
                        {
                            while (!ts.atEnd())
                            {
                                bool isX = false;
                                tmp = readLinefromDataStream(ts);
                                if ((tmp.endsWith("Xa") || tmp.endsWith(" k") || tmp.endsWith(" x")) && (tmp.length() > 4))
                                {
                                    ScTextStream ts2(&tmp, QIODevice::ReadOnly);
                                    ts2 >> c >> m >> y >> k;
                                    if (tmp.endsWith(" x"))
                                    {
                                        isX = true;
                                        int an = tmp.indexOf("(");
                                        int en = tmp.lastIndexOf(")");
                                        FarNam = tmp.mid(an+1, en-an-1);
                                        FarNam = FarNam.simplified();
                                    }
                                    tmp = readLinefromDataStream(ts);
                                    if (tmp.endsWith("Pc"))
                                    {
                                        if (!isX)
                                        {
                                            tmp = tmp.trimmed();
                                            tmp = tmp.remove(0,1);
                                            int en = tmp.indexOf(")");
                                            FarNam = tmp.mid(0, en);
                                            FarNam = FarNam.simplified();
                                        }
                                        cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
                                        cc.setSpotColor(true);
                                        if (!EditColors.contains(FarNam))
                                            EditColors.insert(FarNam, cc);
                                    }
                                }
                            }
                        }
                        if (!isAtend)
                            break;
                    }
                }
int main(int argc, char** argv) {
  init(argc, argv);

  if (argc != 3) {
    google::ShowUsageWithFlags(argv[0]);
    return 1;
  }

  std::string tracks_file = argv[1];
  std::string image_format = argv[2];
  std::string output_format = FLAGS_output_format;

  bool ok;

  TrackList<DrawerPointer> tracks;

  if (FLAGS_similarity) {
    // Load tracks.
    TrackList<SiftPosition> sift_tracks;
    SiftPositionReader feature_reader;
    ok = loadTrackList(tracks_file, sift_tracks, feature_reader);
    CHECK(ok) << "Could not load tracks";

    // Convert SIFT features to generic drawable features.
    siftPositionTracksToDrawers(sift_tracks, tracks);
  } else if (FLAGS_scale) {
    // Load tracks.
    TrackList<ScaleSpacePosition> scale_tracks;
    ScaleSpacePositionReader feature_reader;
    ok = loadTrackList(tracks_file, scale_tracks, feature_reader);
    CHECK(ok) << "Could not load tracks";

    // Convert SIFT features to generic drawable features.
    scaleFeatureTracksToDrawers(scale_tracks, tracks, FLAGS_radius);
  } else {
    // Load tracks.
    TrackList<cv::Point2d> point_tracks;
    ImagePointReader<double> feature_reader;
    ok = loadTrackList(tracks_file, point_tracks, feature_reader);
    CHECK(ok) << "Could not load tracks";

    // Convert SIFT features to generic drawable features.
    translationTracksToDrawers(point_tracks, tracks, FLAGS_radius);
  }

  LOG(INFO) << "Loaded " << tracks.size() << " tracks";

  // Make a list of random colors.
  typedef std::vector<cv::Scalar> ColorList;
  ColorList colors;
  for (int i = 0; i < int(tracks.size()); i += 1) {
    colors.push_back(randomColor(BRIGHTNESS, SATURATION));
  }

  // Iterate through frames in which track was observed.
  TrackListTimeIterator<DrawerPointer> frame(tracks, 0);

  while (!frame.end()) {
    // Get the current time.
    int t = frame.t();

    // Load the image.
    cv::Mat color_image;
    cv::Mat gray_image;
    ok = readImage(makeFilename(image_format, t), color_image, gray_image);
    CHECK(ok) << "Could not read image";

    // Get the features.
    typedef std::map<int, DrawerPointer> FeatureSet;
    FeatureSet features;
    frame.getPoints(features);

    // Draw each one with its color.
    drawFeatures(color_image, features, colors);

    if (FLAGS_save) {
      std::string output_file = makeFilename(output_format, t);
      ok = cv::imwrite(output_file, color_image);
      CHECK(ok) << "Could not save image";
    }

    if (FLAGS_display) {
      cv::imshow("tracks", color_image);
      cv::waitKey(10);
    }

    ++frame;
  }

  return 0;
}