Find the answer to your Linux question:
Results 1 to 6 of 6
hello everybody, i trying to create highlighter for my application using xlib. Is any one have idea about how to create highlighter. if am not wrong,in linux there is no ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9

    how to create highlighter using xlib

    hello everybody,
    i trying to create highlighter for my application using xlib.
    Is any one have idea about how to create highlighter.

    if am not wrong,in linux there is no support for transparency or alpha blending.
    I have done some googling and found that to give support for alpha blending we need to run xcompmgr.But it has other drawbacks.

    Is there any other solution so that i can create highlighter.

    Thanks in advance.

    Regards,
    ~Sanjay

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Maybe alpha blending is too complicated a solution for you.

    If all you want is to show text against, say, a yellow background, where the rest of the background is some solid color, you can follow these steps when drawing text:
    1. Draw the non-text background first.
    2. Set the graphics context so that the background color is yellow.
    3. Use XDrawImageString() instead of XDrawString(), or XDrawImageString16() instead of XDrawString16(). If you're using XDrawText(), or XDrawText16(), you're going to have to break that down into individual XDrawImageString() or XDrawImageString16() calls.
    4. Reset the graphics context to restore the previous background color.

    But a real physical highlighter does more than this. It tends to draw starting a little to the left of the beginning of the text, end a little to the right of the end, and highlight somewhat higher than the top of the text to somewhat lower than the bottom. You'll probably want to do that also. In that case, it's slightly more complicated:
    1. Draw the non-text background first.
    2. Set the graphics context so that the foreground color is yellow.
    3. Use XQueryTextExtents() to find out the bounding box of the text string you wish to display.
    4. Once you've calculated just where the string is to go, use that bounding box to fill the rectangle with yellow. For consistency, don't use the vertical elements of the bounding box as returned by XQueryTextExtents(); that function also returns an overall font ascent and font descent. Use that. This way, the highlighter's thickness will seem the same for xxx as it does for XXX. You'll also want to enlarge the rectangle a little in all four directions; that's the whole point of this more complex method.
    5. Set the graphics context so that the foreground color is the color of the text.
    6. Display the text string in the usual manner, using XDrawString() instead of XDrawImageString(), or whatever your usual method is.

    One disadvantage of this is that it's a little slower; every time you call XQueryTextExtents(), it involves communication with the X server. To save time:
    1. At the beginning of the application for each font you'll be using: After you've loaded the font (so you have the font ID), use XQueryFont() to get the font information structure. If you wish, you can combine your usual XLoadFont() with the XQueryFont(), and call XLoadQueryFont() instead.
    2. Each time you wish to draw a string, use the previously outlined method, but use XTextExtents() instead of XQueryTextExtents(). That saves the extra round trip to the server.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    Hi,
    I m extremely sorry to reply late.

    I dont want solid background color.
    The background color should be semi transparent.This is the way how highlighter works.


    Regards,
    ~Sanjay

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I dont want solid background color.
    The background color should be semi transparent.
    In that case, first draw your image/text/whatever.

    Then, to change that image, you should read in the desired pixels, change them, and write them out. To read and write the desired pixels, use whichever combination of these you desire:
    Code:
    XGetImage()
    XPutImage()
    XGetPixel()
    XPutPixel()
    XAddPixel()
    XSubImage()
    XGetSubImage()
    If you've used XGetImage(), XSubImage(), or XGetSubImage(), you'll want to use XDestroyImage() to avoid memory leaks.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    I got it how to read and write the pixels from image.
    you should read in the desired pixels, change them, and write them out
    But "change them" means to what values should i change so that semi transparency can be achieved.

    can u explain me after reading each pixel what values should i write again.

    Regards,
    ~sanjay

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Quoth sanjayshelke:
    can u explain me after reading each pixel what values should i write again.
    If you want it to look more yellow, add a little something (you'll have to experiment) to the red and green values.

    If the red and green values are already at or near their maximum and there's also enough value in the blue value, subtract something (you'll have to experiment) from the blue value.

    To do this, you'll have to also manipulate the image's pallette. This is a more complex subject than I can explain in a forum like this one. Read about that in one of the many X tutorials that exist on the web. Here's a list.

    For example, the second tutorial on the list speaks about color map allocation here.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...