Juergen Spitzmueller wrote:

>> Store the R,G,B triple...
> 
> This is also what I had in mind, actually. But due to my well-known
> ignorance, it didn't know how this can be done technically (and what color
> format LyX uses).
> 

LyX currently stores an 'X11 colour name' in LColor.[Ch]. Fortunately, you 
can generate it from the R,G,B triple... This code is currently in 
FormPreferences.C. Move it into Color.[Ch] and move these files into 
support.

string const X11hexname(RGBColor const & col)
{
        ostringstream ostr;

        ostr << '#' << std::setbase(16) << setfill('0')
             << setw(2) << col.r
             << setw(2) << col.g
             << setw(2) << col.b;

        return STRCONV(ostr.str());
}

These functions should make reading and writing an RGB color to file simple

ostream & operator<<(ostream & os, RGBColor const & col) 
{
        os << col.r << RGBColor::seperator
           << col.g << RGBColor::seperator
           << col.b;
        return os;
}

istream & operator>>(istream & is, RGBColor & col)
{
        // You'll have to set std::ws() so that it knows about 
        // RGBColor::seperator. Anyone?
        is >> col.r >> std::ws()
           >> col.g >> std::ws()
           >> col.b;
        return is;
}
        

-- 
Angus

Reply via email to