diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index fb74a29a9f5..03a66adab74 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -1349,6 +1349,7 @@ class Categorie extends CommonObject
/**
* Return name and link of category (with picto)
+ * Use ->id, ->ref, ->label, ->color
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param string $option Sur quoi pointe le lien ('', 'xyz')
@@ -1363,13 +1364,18 @@ class Categorie extends CommonObject
$label=$langs->trans("ShowCategory").': '. ($this->ref?$this->ref:$this->label);
// Check contrast with background and correct text color
- $color = colorArrayToHex(colorStringToArray($this->color,array()),'');
- $forced_color='000';
- $tmpcolorweight=0;
- foreach(colorStringToArray($color,array()) as $x) $tmpcolorweight+=$x;
- if ($tmpcolorweight < 400) $forced_color='FFF';
+ $forced_color='categtextwhite';
+ if ($this->color)
+ {
+ $hex=$this->color;
+ $r = hexdec($hex[0].$hex[1]);
+ $g = hexdec($hex[2].$hex[3]);
+ $b = hexdec($hex[4].$hex[5]);
+ $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
+ if ($bright > 0.6) $forced_color='categtextblack'; // Higher than 60%
+ }
- $link = '';
+ $link = '';
$linkend='';
$picto='category';
diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php
index 1727db5f227..078dc01d96f 100644
--- a/htdocs/core/class/html.formother.class.php
+++ b/htdocs/core/class/html.formother.class.php
@@ -595,13 +595,20 @@ class FormOther
*/
static function showColor($color, $textifnotdefined='')
{
+ $textcolor='FFF';
+ if ($color)
+ {
+ $hex=$color;
+ $r = hexdec($hex[0].$hex[1]);
+ $g = hexdec($hex[2].$hex[3]);
+ $b = hexdec($hex[4].$hex[5]);
+ $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
+ if ($bright > 0.6) $textcolor='000';
+ }
+
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-
$color = colorArrayToHex(colorStringToArray($color,array()),'');
- $textcolor='000';
- $tmpcolorweight=0;
- foreach(colorStringToArray($color,array()) as $x) $tmpcolorweight+=$x;
- if ($tmpcolorweight < 400) $textcolor='FFF';
+
if ($color) print '';
else print $textifnotdefined;
}
diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php
index a756e1f941c..1aa5b41ac3f 100644
--- a/htdocs/theme/eldy/style.css.php
+++ b/htdocs/theme/eldy/style.css.php
@@ -3655,22 +3655,31 @@ a span.select2-chosen
overflow: hidden;
}
+
+/* ============================================================================== */
+/* For categories */
+/* ============================================================================== */
+
.noborderoncategories {
border: none !important;
border-radius: 5px !important;
box-shadow: none;
-webkit-box-shadow: none !important;
box-shadow: none !important;
- color: #fff;
}
span.noborderoncategories a, li.noborderoncategories a {
- color: #fff;
line-height: normal;
vertical-align: top;
}
span.noborderoncategories {
padding: 3px 5px 0px 5px;
}
+.categtextwhite, .treeview .categtextwhite.hover {
+ color: #fff !important;
+}
+.categtextblack {
+ color: #000 !important;
+}
/* ============================================================================== */
diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php
index fe1e161dfc8..e08512b9ca4 100644
--- a/htdocs/theme/md/style.css.php
+++ b/htdocs/theme/md/style.css.php
@@ -2789,6 +2789,14 @@ table.dp {
color: rgb();
}
+.categtextwhite, .treeview .categtextwhite.hover {
+ color: #fff !important;
+}
+.categtextblack {
+ color: #000 !important;
+}
+
+
/* ============================================================================== */
/* Afficher/cacher */
/* ============================================================================== */
@@ -3498,22 +3506,30 @@ a span.select2-chosen
overflow: hidden;
}
+
+/* ============================================================================== */
+/* For categories */
+/* ============================================================================== */
+
.noborderoncategories {
border: none !important;
border-radius: 5px !important;
box-shadow: none;
-webkit-box-shadow: none !important;
box-shadow: none !important;
- color: #fff !important;
}
span.noborderoncategories a, li.noborderoncategories a {
- color: #fff !important;
line-height: normal;
}
span.noborderoncategories {
padding: 5px 5px 0px 5px;
}
-
+.categtextwhite, .treeview .categtextwhite.hover {
+ color: #fff !important;
+}
+.categtextblack {
+ color: #000 !important;
+}
/* ============================================================================== */