~cairo-dock-team/ubuntu/natty/cairo-dock/2.3.0-1

« back to all changes in this revision

Viewing changes to src/gldit/cairo-dock-surface-factory.c

  • Committer: matttbe
  • Date: 2010-10-02 18:11:29 UTC
  • Revision ID: matttbe@gmail.com-20101002181129-eeetybt3keeqdf9x
* New Upstream Version (LP: #653702)
* Fixed a few bugs:
 - Fixed a random crash if CD is launched much time before the WM
 - Improved the OpenGL backend.
 - Some Images paths were wrong
 - Icon label text was truncated (LP: #611738)
 - Fixed a bug when the font was too big
 - Gauges: Add a line return in order to read all Readme file
 - Dialogues don't respect selected font (LP: #518628)
* debian/control:
 - Updated the description.
* data/help.conf.in:
 - Removed the Gnome-Panel: Used the right gconf key

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "cairo-dock-launcher-manager.h"
29
29
#include "cairo-dock-container.h"
30
30
#include "cairo-dock-load.h"
 
31
#include "cairo-dock-X-manager.h"
31
32
#include "cairo-dock-surface-factory.h"
32
33
 
33
34
extern CairoContainer *g_pPrimaryContainer;
34
35
extern gboolean g_bUseOpenGL;
 
36
extern CairoDockDesktopGeometry g_desktopGeometry;
35
37
 
36
38
static cairo_t *s_pSourceContext = NULL;
37
39
 
548
550
        if (*cImageFile == '/')
549
551
                cImagePath = (gchar *)cImageFile;
550
552
        else
551
 
                cImagePath = cairo_dock_generate_file_path (cImageFile);
 
553
                cImagePath = cairo_dock_search_image_s_path (cImageFile);
552
554
                
553
555
        cairo_surface_t *pSurface = cairo_dock_create_surface_from_image (cImagePath,
554
556
                1.,
594
596
 
595
597
        if (cImageFile != NULL)
596
598
        {
597
 
                gchar *cImagePath = cairo_dock_generate_file_path (cImageFile);
 
599
                gchar *cImagePath = cairo_dock_search_image_s_path (cImageFile);
598
600
                double fImageWidth, fImageHeight;
599
601
                cairo_surface_t *pPatternSurface = cairo_dock_create_surface_from_image (cImagePath,
600
602
                        1.,
785
787
}
786
788
 
787
789
 
 
790
void cairo_dock_limit_string_width (gchar *cLine, PangoLayout *pLayout, gboolean bUseMarkup, int iMaxWidth)
 
791
{
 
792
        // on insere des retours chariot pour tenir dans la largeur donnee.
 
793
        PangoRectangle ink, log;
 
794
        gchar *sp, *last_sp=NULL;
 
795
        double w;
 
796
        int iNbLines = 0;
 
797
        
 
798
        gchar *str = cLine;
 
799
        while (*str == ' ')  // on saute les espaces en debut de ligne.
 
800
                str ++;
 
801
        
 
802
        sp = str;
 
803
        do
 
804
        {
 
805
                sp = strchr (sp+1, ' ');  // on trouve l'espace suivant.
 
806
                if (!sp)  // plus d'espace, on quitte.
 
807
                        break ;
 
808
                
 
809
                *sp = '\0';  // on coupe a cet espace.
 
810
                if (bUseMarkup)  // on regarde la taille de str a sp.
 
811
                        pango_layout_set_markup (pLayout, str, -1);
 
812
                else
 
813
                        pango_layout_set_text (pLayout, str, -1);
 
814
                pango_layout_get_pixel_extents (pLayout, &ink, &log);
 
815
                //g_print ("%s => w:%d/%d, x:%d/%d\n", str, log.width, ink.width, log.x, ink.x);
 
816
                w = log.width + log.x;
 
817
                
 
818
                if (w > iMaxWidth)  // on deborde.
 
819
                {
 
820
                        if (last_sp != NULL)  // on coupe au dernier espace connu.
 
821
                        {
 
822
                                *sp = ' ';  // on remet l'espace.
 
823
                                *last_sp = '\n';  // on coupe.
 
824
                                iNbLines ++;
 
825
                                str = last_sp + 1;  // on place le debut de ligne apres la coupure.
 
826
                        }
 
827
                        else  // aucun espace, c'est un mot entier.
 
828
                        {
 
829
                                *sp = '\n';  // on coupe apres le mot.
 
830
                                iNbLines ++;
 
831
                                str = sp + 1;  // on place le debut de ligne apres la coupure.
 
832
                        }
 
833
                        
 
834
                        while (*str == ' ')  // on saute les espaces en debut de ligne.
 
835
                                str ++;
 
836
                        sp = str;
 
837
                        last_sp = NULL;
 
838
                }
 
839
                else  // ca rentre.
 
840
                {
 
841
                        *sp = ' ';  // on remet l'espace.
 
842
                        last_sp = sp;  // on memorise la derniere cesure qui fait tenir la ligne en largeur.
 
843
                        sp ++;  // on se place apres.
 
844
                        while (*sp == ' ')  // on saute tous les espaces.
 
845
                                sp ++;
 
846
                }
 
847
        } while (sp);
 
848
        
 
849
        // dernier mot.
 
850
        if (bUseMarkup)  // on regarde la taille de str a sp.
 
851
                pango_layout_set_markup (pLayout, str, -1);
 
852
        else
 
853
                pango_layout_set_text (pLayout, str, -1);
 
854
        pango_layout_get_pixel_extents (pLayout, &ink, &log);
 
855
        w = log.width + log.x;
 
856
        if (w > iMaxWidth)  // on deborde.
 
857
        {
 
858
                if (last_sp != NULL)  // on coupe au dernier espace connu.
 
859
                        *last_sp = '\n';
 
860
        }
 
861
}
 
862
 
788
863
cairo_surface_t *cairo_dock_create_surface_from_text_full (const gchar *cText, CairoDockLabelDescription *pLabelDescription, double fMaxScale, int iMaxWidth, int *iTextWidth, int *iTextHeight, double *fTextXOffset, double *fTextYOffset)
789
864
{
790
865
        g_return_val_if_fail (cText != NULL && pLabelDescription != NULL, NULL);
805
880
        
806
881
        pango_layout_set_text (pLayout, "|", -1);  // donne la hauteur max des lettres.
807
882
        pango_layout_get_pixel_extents (pLayout, &ink, &log);
808
 
        int iMaxSize = ink.height;
 
883
        int iMinSize = ink.height;  // hauteur min = au moins la plus grande lettre pour une uniformite des labels.
809
884
        
810
885
        if (pLabelDescription->bUseMarkup)
811
886
                pango_layout_set_markup (pLayout, cText, -1);
812
887
        else
813
888
                pango_layout_set_text (pLayout, cText, -1);
814
889
        
 
890
        //\_________________ On insere des retours chariot si necessaire.
 
891
        pango_layout_get_pixel_extents (pLayout, &ink, &log);
 
892
        
 
893
        if (pLabelDescription->fMaxRelativeWidth != 0)
 
894
        {
 
895
                int iMaxLineWidth = pLabelDescription->fMaxRelativeWidth * g_desktopGeometry.iScreenWidth[CAIRO_DOCK_HORIZONTAL];
 
896
                int w = ink.width;
 
897
                //g_print ("text width : %d / %d\n", w, iMaxLineWidth);
 
898
                if (w > iMaxLineWidth)  // le texte est trop long.
 
899
                {
 
900
                        // on decoupe le texte en lignes et on limite chaque ligne trop longue.
 
901
                        gchar *sp, *last_sp=NULL;
 
902
                        gchar **cLines = g_strsplit (cText, "\n", -1);
 
903
                        gchar *cLine;
 
904
                        int i;
 
905
                        for (i = 0; cLines[i] != NULL; i ++)
 
906
                        {
 
907
                                cLine = cLines[i];
 
908
                                cairo_dock_limit_string_width (cLine, pLayout, pLabelDescription->bUseMarkup, iMaxLineWidth);
 
909
                                g_print (" + %s\n", cLine);
 
910
                        }
 
911
                        
 
912
                        // on reforme le texte et on le passe a pango.
 
913
                        gchar *cCutText = g_strjoinv ("\n", cLines);
 
914
                        if (pLabelDescription->bUseMarkup)
 
915
                                pango_layout_set_markup (pLayout, cCutText, -1);
 
916
                        else
 
917
                                pango_layout_set_text (pLayout, cCutText, -1);
 
918
                        pango_layout_get_pixel_extents (pLayout, &ink, &log);
 
919
                        g_strfreev (cLines);
 
920
                        g_free (cCutText);
 
921
                }
 
922
        }
 
923
        
815
924
        //\_________________ On cree une surface aux dimensions du texte.
816
 
        pango_layout_get_pixel_extents (pLayout, &ink, &log);
817
 
        
818
925
        gboolean bDrawBackground = (pLabelDescription->fBackgroundColor != NULL && pLabelDescription->fBackgroundColor[3] > 0);
819
926
        double fRadius = fMaxScale * MAX (pLabelDescription->iMargin, MIN (6, pLabelDescription->iSize/3));  // permet d'avoir un rayon meme si on n'a pas de marge.
820
927
        int iOutlineMargin = 2*pLabelDescription->iMargin + (pLabelDescription->bOutlined ? 2 : 0);  // outlined => +1 tout autour des lettres.
821
 
        double fZoomX = ((iMaxWidth != 0 && ink.width + iOutlineMargin > iMaxWidth) ? 1.*iMaxWidth / (ink.width + iOutlineMargin) : 1.);
 
928
        double fZoomX = ((iMaxWidth != 0 && ink.width + iOutlineMargin > iMaxWidth) ? (double)iMaxWidth / (ink.width + iOutlineMargin) : 1.);
822
929
        
823
930
        *iTextWidth = (ink.width + iOutlineMargin) * fZoomX;  // le texte + la marge de chaque cote.
824
931
        if (bDrawBackground)  // quand on trace le cadre, on evite qu'avec des petits textes genre "1" on obtienne un fond tout rond.
827
934
                if (iMaxWidth != 0 && *iTextWidth > iMaxWidth)
828
935
                        *iTextWidth = iMaxWidth;
829
936
        }
830
 
        *iTextHeight = MAX (iMaxSize, ink.height) + iOutlineMargin + 0; // +1 car certaines polices "debordent".
 
937
        *iTextHeight = MAX (iMinSize, ink.height) + iOutlineMargin + 0; // +1 car certaines polices "debordent".
831
938
        
832
939
        cairo_surface_t* pNewSurface = cairo_dock_create_blank_surface (
833
940
                *iTextWidth,