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"
33
34
extern CairoContainer *g_pPrimaryContainer;
34
35
extern gboolean g_bUseOpenGL;
36
extern CairoDockDesktopGeometry g_desktopGeometry;
36
38
static cairo_t *s_pSourceContext = NULL;
790
void cairo_dock_limit_string_width (gchar *cLine, PangoLayout *pLayout, gboolean bUseMarkup, int iMaxWidth)
792
// on insere des retours chariot pour tenir dans la largeur donnee.
793
PangoRectangle ink, log;
794
gchar *sp, *last_sp=NULL;
799
while (*str == ' ') // on saute les espaces en debut de ligne.
805
sp = strchr (sp+1, ' '); // on trouve l'espace suivant.
806
if (!sp) // plus d'espace, on quitte.
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);
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;
818
if (w > iMaxWidth) // on deborde.
820
if (last_sp != NULL) // on coupe au dernier espace connu.
822
*sp = ' '; // on remet l'espace.
823
*last_sp = '\n'; // on coupe.
825
str = last_sp + 1; // on place le debut de ligne apres la coupure.
827
else // aucun espace, c'est un mot entier.
829
*sp = '\n'; // on coupe apres le mot.
831
str = sp + 1; // on place le debut de ligne apres la coupure.
834
while (*str == ' ') // on saute les espaces en debut de ligne.
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.
850
if (bUseMarkup) // on regarde la taille de str a sp.
851
pango_layout_set_markup (pLayout, str, -1);
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.
858
if (last_sp != NULL) // on coupe au dernier espace connu.
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)
790
865
g_return_val_if_fail (cText != NULL && pLabelDescription != NULL, NULL);
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.
810
885
if (pLabelDescription->bUseMarkup)
811
886
pango_layout_set_markup (pLayout, cText, -1);
813
888
pango_layout_set_text (pLayout, cText, -1);
890
//\_________________ On insere des retours chariot si necessaire.
891
pango_layout_get_pixel_extents (pLayout, &ink, &log);
893
if (pLabelDescription->fMaxRelativeWidth != 0)
895
int iMaxLineWidth = pLabelDescription->fMaxRelativeWidth * g_desktopGeometry.iScreenWidth[CAIRO_DOCK_HORIZONTAL];
897
//g_print ("text width : %d / %d\n", w, iMaxLineWidth);
898
if (w > iMaxLineWidth) // le texte est trop long.
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);
905
for (i = 0; cLines[i] != NULL; i ++)
908
cairo_dock_limit_string_width (cLine, pLayout, pLabelDescription->bUseMarkup, iMaxLineWidth);
909
g_print (" + %s\n", cLine);
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);
917
pango_layout_set_text (pLayout, cCutText, -1);
918
pango_layout_get_pixel_extents (pLayout, &ink, &log);
815
924
//\_________________ On cree une surface aux dimensions du texte.
816
pango_layout_get_pixel_extents (pLayout, &ink, &log);
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.);
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.