예제 #1
0
        /// <summary>
        /// Fixes the GPS Timestamp in EXIF. </summary>
        /// <param name="exifSchema"> the EXIF schema node </param>
        /// <exception cref="XmpException"> Thrown if the date conversion fails. </exception>
        private static void FixGpsTimeStamp(XmpNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XmpNode gpsDateTime = XmpNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }

            try {
                XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.Value);
                if (binGpsStamp.Year != 0 || binGpsStamp.Month != 0 || binGpsStamp.Day != 0)
                {
                    return;
                }

                XmpNode otherDate = XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                otherDate = otherDate ?? XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);

                XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.Value);
                XmpCalendar cal          = binGpsStamp.Calendar;
                DateTime    dt           = new DateTime(binOtherDate.Year, binOtherDate.Month, binOtherDate.Day, cal.DateTime.Hour,
                                                        cal.DateTime.Minute, cal.DateTime.Second, cal.DateTime.Millisecond);
                cal.DateTime      = dt;
                binGpsStamp       = new XmpDateTimeImpl(cal);
                gpsDateTime.Value = XMPUtils.ConvertFromDate(binGpsStamp);
            }
            catch (XmpException) {
            }
        }
예제 #2
0
        /// <summary>Fixes the GPS Timestamp in EXIF.</summary>
        /// <param name="exifSchema">the EXIF schema node</param>
        /// <exception cref="iText.Kernel.XMP.XMPException">Thrown if the date conversion fails.
        ///     </exception>
        private static void FixGPSTimeStamp(XMPNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }

            try {
                XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue());
                if (binGpsStamp.GetYear() != 0 || binGpsStamp.GetMonth() != 0 || binGpsStamp.GetDay() != 0)
                {
                    return;
                }

                XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                otherDate = otherDate ?? XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);

                XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue());
                XMPCalendar cal          = binGpsStamp.GetCalendar();
                DateTime    dt           = new DateTime(binOtherDate.GetYear(), binOtherDate.GetMonth(), binOtherDate.GetDay(),
                                                        cal.GetDateTime().Hour, cal.GetDateTime().Minute, cal.GetDateTime().Second, cal.GetDateTime().Millisecond);
                cal.SetDateTime(dt);
                binGpsStamp = new XMPDateTimeImpl(cal);
                gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGpsStamp));
            }
            catch (XMPException) {
            }
        }
예제 #3
0
        /// <summary>Fixes the GPS Timestamp in EXIF.</summary>
        /// <param name="exifSchema">the EXIF schema node</param>
        /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown if the date conversion fails.</exception>
        private static void FixGPSTimeStamp(XMPNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }
            try
            {
                XMPDateTime binGPSStamp;
                XMPDateTime binOtherDate;
                binGPSStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue());
                if (binGPSStamp.GetYear() != 0 || binGPSStamp.GetMonth() != 0 || binGPSStamp.GetDay() != 0)
                {
                    return;
                }
                XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                if (otherDate == null)
                {
                    otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);
                }
                binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue());
                Sharpen.Calendar cal = binGPSStamp.GetCalendar();
                cal.Set(Sharpen.CalendarEnum.Year, binOtherDate.GetYear());
                cal.Set(Sharpen.CalendarEnum.Month, binOtherDate.GetMonth());
                cal.Set(Sharpen.CalendarEnum.DayOfMonth, binOtherDate.GetDay());
                binGPSStamp = new XMPDateTimeImpl(cal);
                gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGPSStamp));
            }
            catch (XMPException)
            {
                // Don't let a missing or bad date stop other things.
                return;
            }
        }
예제 #4
0
		/// <summary>
		/// Evaluates a raw node value to the given value type, apply special
		/// conversions for defined types in XMP.
		/// </summary>
		/// <param name="valueType">an int indicating the value type</param>
		/// <param name="propNode">the node containing the value</param>
		/// <returns>Returns a literal value for the node.</returns>
		/// <exception cref="iText.Kernel.XMP.XMPException">
		/// if the value of <code>propNode</code> is <code>null</code> or empty or the conversion fails.
		/// </exception>
		private Object EvaluateNodeValue(int valueType, XMPNode propNode)
		{
			Object value;
			String rawValue = propNode.GetValue();
			switch (valueType)
			{
				case VALUE_BOOLEAN:
				{
					value = XMPUtils.ConvertToBoolean(rawValue);
					break;
				}

				case VALUE_INTEGER:
				{
					value = XMPUtils.ConvertToInteger(rawValue);
					break;
				}

				case VALUE_LONG:
				{
					value = XMPUtils.ConvertToLong(rawValue);
					break;
				}

				case VALUE_DOUBLE:
				{
					value = XMPUtils.ConvertToDouble(rawValue);
					break;
				}

				case VALUE_DATE:
				{
					value = XMPUtils.ConvertToDate(rawValue);
					break;
				}

				case VALUE_CALENDAR:
				{
					XMPDateTime dt = XMPUtils.ConvertToDate(rawValue);
					value = dt.GetCalendar();
					break;
				}

				case VALUE_BASE64:
				{
					value = XMPUtils.DecodeBase64(rawValue);
					break;
				}

				case VALUE_STRING:
				default:
				{
					// leaf values return empty string instead of null
					// for the other cases the converter methods provides a "null"
					// value.
					// a default value can only occur if this method is made public.
					value = rawValue != null || propNode.GetOptions().IsCompositeProperty() ? rawValue
						 : "";
					break;
				}
			}
			return value;
		}