diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 55d80b82..8150c4a9 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2625,14 +2625,33 @@ namespace Exiv2 { { std::ios::fmtflags f( os.flags() ); if (value.count() == 3) { - static const char* unit[] = { " deg", "'", "\"" }; - for (int i = 0; i < value.count() ; ++i) { - const int v = (int) (value.toFloat(i)+0.5f); // nearest integer - os << (i != 0? " " : "") << v << unit[i]; + Rational deg = value.toRational(0); + Rational min = value.toRational(1); + Rational sec = value.toRational(2); + if ((deg.second != 1) || (min.second == 0) || (sec.second == 0)) { + return os << "(" << value << ")"; } + const int32_t dd = deg.first; + const int32_t mm = min.first / min.second; + const int32_t rem = min.first % min.second; + if ((min.second > 1) && (rem > 0)) { + if ((sec.first == 0) && (sec.second == 1)) { + sec.first = 60 * rem; + sec.second = min.second; + } else { + return os << "(" << value << ")"; + } + } + const float ss = (float)sec.first / sec.second; + os << dd << " deg "; + os << mm << "' "; + std::ostringstream oss; + oss.copyfmt(os); + os << std::fixed << std::setprecision(sec.second > 1 ? 2 : 0) << ss << "\""; + os.copyfmt(oss); } else { - os << value; + os << "(" << value << ")"; } os.flags(f); return os; diff --git a/tests/bugfixes/redmine/test_issue_1024.py b/tests/bugfixes/redmine/test_issue_1024.py index 07a83209..8a3a3ac4 100644 --- a/tests/bugfixes/redmine/test_issue_1024.py +++ b/tests/bugfixes/redmine/test_issue_1024.py @@ -10,9 +10,9 @@ class CheckRegularExpressionSupport(metaclass=system_tests.CaseMeta): commands = [ "$exiv2 -pa --grep gpsl/i $filename" ] stdout = [ """Exif.GPSInfo.GPSLatitudeRef Ascii 2 North -Exif.GPSInfo.GPSLatitude Rational 3 52 deg 4' 0" +Exif.GPSInfo.GPSLatitude Rational 3 52 deg 3' 49.02" Exif.GPSInfo.GPSLongitudeRef Ascii 2 East -Exif.GPSInfo.GPSLongitude Rational 3 1 deg 14' 0" +Exif.GPSInfo.GPSLongitude Rational 3 1 deg 13' 49.16" """ ] stderr = [""] diff --git a/tests/bugfixes/redmine/test_issue_1137.py b/tests/bugfixes/redmine/test_issue_1137.py index 51b30d48..d6d0293e 100644 --- a/tests/bugfixes/redmine/test_issue_1137.py +++ b/tests/bugfixes/redmine/test_issue_1137.py @@ -36,8 +36,8 @@ set Exif.GPSInfo.GPSLongitude 1/1 495984/10000 0/1 output_grep_GPSL, "", """Exif.GPSInfo.GPSLatitudeRef Ascii 2 North -Exif.GPSInfo.GPSLatitude Rational 3 51 deg 11' 0" +Exif.GPSInfo.GPSLatitude Rational 3 51 deg 10' 41.81" Exif.GPSInfo.GPSLongitudeRef Ascii 2 West -Exif.GPSInfo.GPSLongitude Rational 3 1 deg 50' 0" +Exif.GPSInfo.GPSLongitude Rational 3 1 deg 49' 35.90" """ ] diff --git a/tests/bugfixes/redmine/test_issue_528.py b/tests/bugfixes/redmine/test_issue_528.py index c3012eff..635fa9d3 100644 --- a/tests/bugfixes/redmine/test_issue_528.py +++ b/tests/bugfixes/redmine/test_issue_528.py @@ -69,9 +69,9 @@ Exif.Photo.Saturation Short 1 Normal Exif.Image.GPSTag Long 1 870 Exif.GPSInfo.GPSVersionID Byte 4 2.0.0.0 Exif.GPSInfo.GPSLatitudeRef Ascii 2 North -Exif.GPSInfo.GPSLatitude Rational 3 47 deg 36' 58" +Exif.GPSInfo.GPSLatitude Rational 3 47 deg 36' 58.02" Exif.GPSInfo.GPSLongitudeRef Ascii 2 East -Exif.GPSInfo.GPSLongitude Rational 3 1 deg 31' 1" +Exif.GPSInfo.GPSLongitude Rational 3 1 deg 31' 0.94" Exif.GPSInfo.GPSAltitudeRef Byte 1 Above sea level Exif.GPSInfo.GPSAltitude Rational 1 86 m Exif.Thumbnail.Compression Short 1 JPEG (old-style)