Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/unit.c')
-rw-r--r--source/blender/blenkernel/intern/unit.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 133f858e9ea..963cfdbea1b 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -44,7 +44,8 @@ typedef struct bUnitDef {
char *name;
char *name_plural; /* abused a bit for the display name */
char *name_short; /* this is used for display*/
- char *name_alt; /* can be NULL */
+ char *name_alt; /* keyboard-friendly ASCII-only version of name_short, can be NULL */
+ /* if name_short has non-ASCII chars, name_alt should be present */
char *name_display; /* can be NULL */
@@ -76,7 +77,7 @@ static struct bUnitCollection buDummyCollecton = {buDummyDef, 0, 0, sizeof(buDum
static struct bUnitDef buMetricLenDef[] = {
{"kilometer", "kilometers", "km", NULL, "Kilometers", 1000.0, 0.0, B_UNIT_DEF_NONE},
{"hectometer", "hectometers", "hm", NULL, "100 Meters", 100.0, 0.0, B_UNIT_DEF_SUPPRESS},
- {"dekameter", "dekameters", "dkm",NULL, "10 Meters", 10.0, 0.0, B_UNIT_DEF_SUPPRESS},
+ {"dekameter", "dekameters", "dam",NULL, "10 Meters", 10.0, 0.0, B_UNIT_DEF_SUPPRESS},
{"meter", "meters", "m", NULL, "Meters", 1.0, 0.0, B_UNIT_DEF_NONE}, /* base unit */
{"decimetre", "decimetres", "dm", NULL, "10 Centimeters", 0.1, 0.0, B_UNIT_DEF_SUPPRESS},
{"centimeter", "centimeters", "cm", NULL, "Centimeters", 0.01, 0.0, B_UNIT_DEF_NONE},
@@ -543,6 +544,49 @@ int bUnit_ReplaceString(char *str, int len_max, char *str_prev, double scale_pre
return change;
}
+/* 45µm --> 45um */
+void bUnit_ToUnitAltName(char *str, int len_max, char *orig_str, int system, int type)
+{
+ bUnitCollection *usys = unit_get_system(system, type);
+
+ bUnitDef *unit;
+ bUnitDef *unit_def= unit_default(usys);
+
+ /* find and substitute all units */
+ for(unit= usys->units; unit->name; unit++) {
+ if(len_max > 0 && (unit->name_alt || unit == unit_def))
+ {
+ char *found= NULL;
+
+ found= unit_find_str(orig_str, unit->name_short);
+ if(found) {
+ int offset= found - orig_str;
+ int len_name= 0;
+
+ /* copy everything before the unit */
+ offset= (offset<len_max? offset: len_max);
+ strncpy(str, orig_str, offset);
+
+ str+= offset;
+ orig_str+= offset + strlen(unit->name_short);
+ len_max-= offset;
+
+ /* print the alt_name */
+ if(unit->name_alt)
+ len_name= snprintf(str, len_max, "%s", unit->name_alt);
+ else
+ len_name= 0;
+
+ len_name= (len_name<len_max? len_name: len_max);
+ str+= len_name;
+ len_max-= len_name;
+ }
+ }
+ }
+
+ /* finally copy the rest of the string */
+ strncpy(str, orig_str, len_max);
+}
double bUnit_ClosestScalar(double value, int system, int type)
{