예제 #1
0
        public void ApproxEqualsFalse()
        {
            float a         = 0f;
            float b         = 1f;
            float tolerance = 0f;

            Assert.IsFalse(a.ApproxEquals(b, tolerance));
            tolerance = 0.5f;
            Assert.IsFalse(a.ApproxEquals(b, tolerance));
        }
예제 #2
0
        private float calculateFontSize(float w, float h)
        {
            BaseFont ufont = RealFont;
            float    fsize = fontSize;

            if (fsize.ApproxEquals(0))
            {
                float bw = ufont.GetWidthPoint(text, 1);
                if (bw.ApproxEquals(0))
                {
                    fsize = 12;
                }
                else
                {
                    fsize = w / bw;
                }
                float nfsize = h / (1 - ufont.GetFontDescriptor(BaseFont.DESCENT, 1));
                fsize = Math.Min(fsize, nfsize);
                if (fsize < 4)
                {
                    fsize = 4;
                }
            }
            return(fsize);
        }
예제 #3
0
 /// <summary>
 /// Attempts to match the target angle to set the control at the correct angle if the drive is no longer moving.
 /// </summary>
 /// <param name="driveSpeed">The speed the drive is automatically rotating at.</param>
 protected virtual void MatchActualTargetAngle(float driveSpeed)
 {
     if (Facade.MoveToTargetValue && driveSpeed.ApproxEquals(0f))
     {
         GetDriveTransform().localRotation = Quaternion.Euler(-AxisDirection * ActualTargetAngle);
     }
 }
 /// <inheritdoc />
 protected override void ProcessAutoDrive(float driveSpeed)
 {
     if (Facade.MoveToTargetValue && !driveSpeed.ApproxEquals(0f))
     {
         GetDriveTransform().localRotation *= Quaternion.Euler(-AxisDirection * driveSpeed * Time.deltaTime);
     }
 }
예제 #5
0
        /// <summary>
        /// Applies the given <see cref="Color"/> to the cameras via <see cref="CameraValidity"/> over the given duration.
        /// </summary>
        /// <param name="newColor"><see cref="Color"/> to apply to the overlay.</param>
        /// <param name="duration">The duration over which the <see cref="Color"/> is applied.</param>
        protected virtual void ApplyColorOverlay(Color newColor, float duration)
        {
            CancelBlinkRoutine();

            if (newColor != targetColor || !duration.ApproxEquals(targetDuration))
            {
                targetDuration = duration;
                targetColor    = newColor;
                if (duration > 0.0f)
                {
                    deltaColor = (targetColor - currentColor) / duration;
                }
                else
                {
                    currentColor = newColor;
                }

                IsAddTransitioning    = false;
                IsRemoveTransitioning = false;
                if (newColor != Color.clear)
                {
                    IsAddTransitioning = true;
                    Added?.Invoke(eventData.Set(newColor));
                }
                else
                {
                    IsRemoveTransitioning = true;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Replaces the attributes that are equal to null with
        /// the attributes of a given font.
        /// </summary>
        /// <param name="font">the font of a bigger element class</param>
        /// <returns>a Font</returns>
        public virtual Font Difference(Font font)
        {
            if (font == null)
            {
                return(this);
            }
            // size
            float dSize = font._size;

            if (dSize.ApproxEquals(UNDEFINED))
            {
                dSize = _size;
            }
            // style
            int dStyle = UNDEFINED;
            int style1 = Style;
            int style2 = font.Style;

            if (style1 != UNDEFINED || style2 != UNDEFINED)
            {
                if (style1 == UNDEFINED)
                {
                    style1 = 0;
                }
                if (style2 == UNDEFINED)
                {
                    style2 = 0;
                }
                dStyle = style1 | style2;
            }
            // color
            object dColor = font.Color;

            if (dColor == null)
            {
                dColor = Color;
            }
            // family
            if (font._baseFont != null)
            {
                return(new Font(font.BaseFont, dSize, dStyle, (BaseColor)dColor));
            }
            if (font.Family != UNDEFINED)
            {
                return(new Font(font.Family, dSize, dStyle, (BaseColor)dColor));
            }
            if (_baseFont != null)
            {
                if (dStyle == style1)
                {
                    return(new Font(BaseFont, dSize, dStyle, (BaseColor)dColor));
                }
                else
                {
                    return(FontFactory.GetFont(Familyname, dSize, dStyle, (BaseColor)dColor));
                }
            }
            return(new Font(Family, dSize, dStyle, (BaseColor)dColor));
        }
예제 #7
0
 /// <summary>
 /// Checks if the properties of this font are undefined or null.
 ///
 /// If so, the standard should be used.
 /// </summary>
 /// <returns>a boolean</returns>
 public virtual bool IsStandardFont()
 {
     return(_family == UNDEFINED &&
            _size.ApproxEquals(UNDEFINED) &&
            _style == UNDEFINED &&
            _color == null &&
            _baseFont == null);
 }
예제 #8
0
        public void ApproxEqualsTrue()
        {
            float a         = 0f;
            float b         = 0f;
            float tolerance = 0f;

            Assert.IsTrue(a.ApproxEquals(b, tolerance));
            tolerance = 1f;
            Assert.IsTrue(a.ApproxEquals(b, tolerance));
            b = 0.5f;
            Assert.IsTrue(a.ApproxEquals(b, tolerance));

            a         = .33333f;
            b         = (float)1 / 3;
            tolerance = .0001f;

            Assert.IsTrue(a.ApproxEquals(b, tolerance));
        }
예제 #9
0
        /// <summary>
        /// Calculates a multiplier based on the direction the rotation is traveling.
        /// </summary>
        /// <returns>The multiplier that represents the direction.</returns>
        protected virtual float CalculateDirectionMultiplier()
        {
            float actualAngle = ActualTargetAngle;

            if (actualAngle.ApproxEquals(currentPseudoRotation, TargetValueReachedThreshold))
            {
                return(0f);
            }

            return(actualAngle > currentPseudoRotation ? 1f : -1f);
        }
예제 #10
0
 /// <inheritdoc />
 public override void ProcessDriveSpeed(float driveSpeed, bool moveToTargetValue)
 {
     PropertyApplier.TransitionDuration = driveSpeed.ApproxEquals(0f) ? 0f : 1f / driveSpeed;
     PropertyApplier.enabled            = moveToTargetValue;
     if (PropertyApplier.enabled)
     {
         if (Interactable.Configuration.ConsumerRigidbody != null)
         {
             Interactable.Configuration.ConsumerRigidbody.velocity = Vector3.zero;
         }
         PropertyApplier.Apply();
     }
 }
예제 #11
0
        /// <summary>
        /// Calculates the rotational angle for an axis based on the difference between two points around the origin.
        /// </summary>
        float CalculateAngle(Vector3 originDirection)
        {
            Vector3 heading          = source.position - target.position;
            float   headingMagnitude = heading.magnitude;
            Vector3 sideA            = previousSourcePosition - target.position;

            if (headingMagnitude.ApproxEquals(0f))
            {
                return(0f);
            }

            Vector3 sideB = heading * (1f / headingMagnitude);

            return(Mathf.Atan2(Vector3.Dot(originDirection, Vector3.Cross(sideA, sideB)), Vector3.Dot(sideA, sideB)) * Mathf.Rad2Deg);
        }
예제 #12
0
        /// <summary>
        /// Calculates the rotational angle for an axis based on the difference between two points around the origin.
        ///
        ///
        ///
        /// </summary>
        public static float CalcAngle(Vector3 originDirection, Vector3 currentPoint, Vector3 prevPoint, Vector3 grabOffset)
        {
            Vector3 relDir = currentPoint - grabOffset;
            float   relMag = relDir.magnitude;
            Vector3 sideA  = prevPoint - grabOffset;

            if (relMag.ApproxEquals(0f))
            {
                return(0f);
            }

            Vector3 sideB = relDir * (1f / relMag);

            return(Mathf.Atan2(Vector3.Dot(originDirection, Vector3.Cross(sideA, sideB)), Vector3.Dot(sideA, sideB)) * Mathf.Rad2Deg);
        }
        /// <summary>
        /// Calculates the rotational angle for an axis based on the difference between two points around the origin.
        /// </summary>
        /// <param name="originDirection">The direction representing the axis.</param>
        /// <param name="originPoint">The angle centre.</param>
        /// <param name="pointA">The first point to calculate the angle from.</param>
        /// <param name="pointB">The second point to calculate the angle to.</param>
        /// <returns>The angle in degrees between the two points.</returns>
        protected virtual float CalculateAngle(Vector3 originDirection, Vector3 originPoint, Vector3 pointA, Vector3 pointB)
        {
            Vector3 heading          = pointB - originPoint;
            float   headingMagnitude = heading.magnitude;
            Vector3 sideA            = pointA - originPoint;

            if (headingMagnitude.ApproxEquals(0f))
            {
                return(0f);
            }

            Vector3 sideB = heading * (1f / headingMagnitude);

            return(Mathf.Atan2(Vector3.Dot(originDirection, Vector3.Cross(sideA, sideB)), Vector3.Dot(sideA, sideB)) * Mathf.Rad2Deg);
        }
예제 #14
0
 /// <summary>
 /// Applies final transformations to the given <see cref="TransformData"/>.
 /// </summary>
 /// <param name="givenSource">The source <see cref="TransformData"/> to obtain the transformation properties from.</param>
 /// <param name="givenTarget">The target <see cref="TransformData"/> to apply transformations to.</param>
 protected virtual void ProcessTransform(TransformData givenSource, TransformData givenTarget)
 {
     if (transitionDuration.ApproxEquals(0f))
     {
         givenTarget.transform.SetGlobalScale(finalScale);
         givenTarget.transform.position = finalPosition;
         givenTarget.transform.rotation = finalRotation;
         AfterTransformUpdated?.Invoke(eventData.Set(givenSource, givenTarget));
     }
     else
     {
         CancelTransition();
         transitionRoutine = StartCoroutine(TransitionTransform(givenSource, givenTarget, givenTarget.Position, finalPosition, givenTarget.Rotation, finalRotation, givenTarget.Scale, finalScale));
     }
 }
예제 #15
0
        /// <summary>
        /// Replaces the attributes that are equal to <VAR>null</VAR> with
        /// the attributes of a given font.
        /// </summary>
        /// <param name="font">The surrounding font</param>
        /// <returns>A RtfFont</returns>
        public override Font Difference(Font font)
        {
            string dFamilyname = font.Familyname;

            if (dFamilyname == null || dFamilyname.Trim().Equals("") || Util.EqualsIgnoreCase(dFamilyname.Trim(), "unknown"))
            {
                dFamilyname = _fontName;
            }

            float dSize = font.Size;

            if (dSize.ApproxEquals(UNDEFINED))
            {
                dSize = Size;
            }

            int dStyle = UNDEFINED;

            if (Style != UNDEFINED && font.Style != UNDEFINED)
            {
                dStyle = Style | font.Style;
            }
            else if (Style != UNDEFINED)
            {
                dStyle = Style;
            }
            else if (font.Style != UNDEFINED)
            {
                dStyle = font.Style;
            }

            BaseColor dColor = font.Color;

            if (dColor == null)
            {
                dColor = Color;
            }

            int dCharset = _charset;

            if (font is RtfFont)
            {
                dCharset = ((RtfFont)font).GetCharset();
            }

            return(new RtfFont(dFamilyname, dSize, dStyle, dColor, dCharset));
        }
예제 #16
0
        public override void Process()
        {
            base.Process();

            previousActualRotation = currentActualRotation;
            currentActualRotation  = GetSimpleEulerAngles();

            CalculateRotationMultiplier();
            AttemptApplyLimits();

            currentPseudoRotation  = CurrentActualAngle + (circleDegrees * rotationMultiplier);
            pseudoAngularVelocity  = !currentPseudoRotation.ApproxEquals(previousPseudoRotation) ? previousPseudoRotation - currentPseudoRotation : pseudoAngularVelocity;
            previousPseudoRotation = currentPseudoRotation;

            float autoDriveTargetVelocity = CalculateAutoDriveVelocity();

            ProcessAutoDrive(autoDriveTargetVelocity);
            MatchActualTargetAngle(autoDriveTargetVelocity);
        }
예제 #17
0
        /// <summary>
        /// Attempts to scale the target.
        /// </summary>
        protected virtual void Scale()
        {
            previousDistance = previousDistance == null?GetDistance() : previousDistance;

            if (CalculateByPower)
            {
                float previousDistanceValue = (float)previousDistance;
                if (!previousDistanceValue.ApproxEquals(0))
                {
                    ScaleByPower();
                }
            }
            else
            {
                ScaleByMultiplier();
            }

            previousDistance = GetDistance();
        }
        public void NotifyTryGrabbed()
        {
            if (!precogTime.ApproxEquals(0))
            {
                if (touch.touchedObjects.Count == 0)
                {
                    StartCoroutine(PrecogTimer.GrabPrecogCoroutine(precogTime, this, NotifyTryGrabbed));
                }
            }

            var bestInteractableRaw = touch.GetBestInteractable();

            if (bestInteractableRaw)
            {
                grab.Grab(bestInteractableRaw);
                Grabbed?.Invoke(bestInteractableRaw);
                //bestInteractableRaw.grab.NotifyGrab(this);
            }
        }
예제 #19
0
        /// <summary>
        /// Applies the given <see cref="Color"/> to the cameras via <see cref="CameraValidity"/> over the given duration.
        /// </summary>
        /// <param name="newColor"><see cref="Color"/> to apply to the overlay.</param>
        /// <param name="duration">The duration over which the <see cref="Color"/> is applied.</param>
        protected virtual void AddColorOverlay(Color newColor, float duration)
        {
            CancelBlinkRoutine();

            if (newColor != targetColor || !duration.ApproxEquals(targetDuration))
            {
                targetDuration = duration;
                targetColor    = newColor;
                if (duration > 0.0f)
                {
                    deltaColor = (targetColor - currentColor) / duration;
                }
                else
                {
                    currentColor = newColor;
                }

                if (newColor != Color.clear)
                {
                    Added?.Invoke(eventData.Set(newColor));
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Creates a <see cref= "Quaternion"/> that represents a rotation around any axis.
 /// </summary>
 /// <param name="axis">Axis that will be rotated around.</param>
 /// <param name="angle">Angle to rotate by.</param>
 /// <returns>A rotation <see cref="Quaternion"/>.</returns>
 public static Quaternion QuaternionRotate(Vector3D axis, float angle) => angle.ApproxEquals(0, 1E-6f) ? Quaternion.Identity : new Quaternion(Cos(angle / 2), axis.Normalise() * Sin(angle / 2)).Normalise();
예제 #21
0
        /// <summary>
        /// Get the  PdfAppearance  of a text or combo field
        /// @throws IOException on error
        /// @throws DocumentException on error
        /// </summary>
        /// <returns>A  PdfAppearance </returns>
        public PdfAppearance GetAppearance()
        {
            PdfAppearance app = GetBorderAppearance();

            app.BeginVariableText();
            if (string.IsNullOrEmpty(text))
            {
                app.EndVariableText();
                return(app);
            }
            bool  borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
            float h           = box.Height - borderWidth * 2 - _extraMarginTop;
            float bw2         = borderWidth;

            if (borderExtra)
            {
                h   -= borderWidth * 2;
                bw2 *= 2;
            }
            float offsetX = Math.Max(bw2, 1);
            float offX    = Math.Min(bw2, offsetX);

            app.SaveState();
            app.Rectangle(offX, offX, box.Width - 2 * offX, box.Height - 2 * offX);
            app.Clip();
            app.NewPath();
            string ptext;

            if ((options & PASSWORD) != 0)
            {
                ptext = ObfuscatePassword(text);
            }
            else if ((options & MULTILINE) == 0)
            {
                ptext = RemoveCrlf(text);
            }
            else
            {
                ptext = text; //fixed by Kazuya Ujihara (ujihara.jp)
            }
            BaseFont  ufont  = RealFont;
            BaseColor fcolor = (textColor == null) ? GrayColor.Grayblack : textColor;
            int       rtl    = checkRtl(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
            float     usize  = fontSize;
            Phrase    phrase = composePhrase(ptext, ufont, fcolor, usize);

            if ((options & MULTILINE) != 0)
            {
                float      width  = box.Width - 4 * offsetX - _extraMarginLeft;
                float      factor = ufont.GetFontDescriptor(BaseFont.BBOXURY, 1) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, 1);
                ColumnText ct     = new ColumnText(null);
                if (usize.ApproxEquals(0))
                {
                    usize = h / factor;
                    if (usize > 4)
                    {
                        if (usize > 12)
                        {
                            usize = 12;
                        }
                        float step = Math.Max((usize - 4) / 10, 0.2f);
                        ct.SetSimpleColumn(0, -h, width, 0);
                        ct.Alignment    = alignment;
                        ct.RunDirection = rtl;
                        for (; usize > 4; usize -= step)
                        {
                            ct.YLine = 0;
                            changeFontSize(phrase, usize);
                            ct.SetText(phrase);
                            ct.Leading = factor * usize;
                            int status = ct.Go(true);
                            if ((status & ColumnText.NO_MORE_COLUMN) == 0)
                            {
                                break;
                            }
                        }
                    }
                    if (usize < 4)
                    {
                        usize = 4;
                    }
                }
                changeFontSize(phrase, usize);
                ct.Canvas = app;
                float leading = usize * factor;
                float offsetY = offsetX + h - ufont.GetFontDescriptor(BaseFont.BBOXURY, usize);
                ct.SetSimpleColumn(_extraMarginLeft + 2 * offsetX, -20000, box.Width - 2 * offsetX, offsetY + leading);
                ct.Leading      = leading;
                ct.Alignment    = alignment;
                ct.RunDirection = rtl;
                ct.SetText(phrase);
                ct.Go();
            }
            else
            {
                if (usize.ApproxEquals(0))
                {
                    float maxCalculatedSize = h / (ufont.GetFontDescriptor(BaseFont.BBOXURX, 1) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, 1));
                    changeFontSize(phrase, 1);
                    float wd = ColumnText.GetWidth(phrase, rtl, 0);
                    if (wd.ApproxEquals(0))
                    {
                        usize = maxCalculatedSize;
                    }
                    else
                    {
                        usize = Math.Min(maxCalculatedSize, (box.Width - _extraMarginLeft - 4 * offsetX) / wd);
                    }
                    if (usize < 4)
                    {
                        usize = 4;
                    }
                }
                changeFontSize(phrase, usize);
                float offsetY = offX + ((box.Height - 2 * offX) - ufont.GetFontDescriptor(BaseFont.ASCENT, usize)) / 2;
                if (offsetY < offX)
                {
                    offsetY = offX;
                }
                if (offsetY - offX < -ufont.GetFontDescriptor(BaseFont.DESCENT, usize))
                {
                    float ny = -ufont.GetFontDescriptor(BaseFont.DESCENT, usize) + offX;
                    float dy = box.Height - offX - ufont.GetFontDescriptor(BaseFont.ASCENT, usize);
                    offsetY = Math.Min(ny, Math.Max(offsetY, dy));
                }
                if ((options & COMB) != 0 && maxCharacterLength > 0)
                {
                    int textLen  = Math.Min(maxCharacterLength, ptext.Length);
                    int position = 0;
                    if (alignment == Element.ALIGN_RIGHT)
                    {
                        position = maxCharacterLength - textLen;
                    }
                    else if (alignment == Element.ALIGN_CENTER)
                    {
                        position = (maxCharacterLength - textLen) / 2;
                    }
                    float step  = (box.Width - _extraMarginLeft) / maxCharacterLength;
                    float start = step / 2 + position * step;
                    if (textColor == null)
                    {
                        app.SetGrayFill(0);
                    }
                    else
                    {
                        app.SetColorFill(textColor);
                    }
                    app.BeginText();
                    foreach (Chunk ck in phrase)
                    {
                        BaseFont bf = ck.Font.BaseFont;
                        app.SetFontAndSize(bf, usize);
                        StringBuilder sb = ck.Append("");
                        for (int j = 0; j < sb.Length; ++j)
                        {
                            string c  = sb.ToString(j, 1);
                            float  wd = bf.GetWidthPoint(c, usize);
                            app.SetTextMatrix(_extraMarginLeft + start - wd / 2, offsetY - _extraMarginTop);
                            app.ShowText(c);
                            start += step;
                        }
                    }
                    app.EndText();
                }
                else
                {
                    float x;
                    switch (alignment)
                    {
                    case Element.ALIGN_RIGHT:
                        x = _extraMarginLeft + box.Width - (2 * offsetX);
                        break;

                    case Element.ALIGN_CENTER:
                        x = _extraMarginLeft + (box.Width / 2);
                        break;

                    default:
                        x = _extraMarginLeft + (2 * offsetX);
                        break;
                    }
                    ColumnText.ShowTextAligned(app, alignment, phrase, x, offsetY - _extraMarginTop, 0, rtl, 0);
                }
            }
            app.RestoreState();
            app.EndVariableText();
            return(app);
        }
예제 #22
0
        /// <summary>
        /// Get the  PdfAppearance  of a list field
        /// @throws IOException on error
        /// @throws DocumentException on error
        /// </summary>
        /// <returns>A  PdfAppearance </returns>
        internal PdfAppearance GetListAppearance()
        {
            PdfAppearance app = GetBorderAppearance();

            app.BeginVariableText();
            if (_choices == null || _choices.Length == 0)
            {
                app.EndVariableText();
                return(app);
            }
            int topChoice = _choiceSelection;

            if (topChoice >= _choices.Length)
            {
                topChoice = _choices.Length - 1;
            }
            if (topChoice < 0)
            {
                topChoice = 0;
            }
            BaseFont ufont = RealFont;
            float    usize = fontSize;

            if (usize.ApproxEquals(0))
            {
                usize = 12;
            }
            bool  borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
            float h           = box.Height - borderWidth * 2;
            float offsetX     = borderWidth;

            if (borderExtra)
            {
                h       -= borderWidth * 2;
                offsetX *= 2;
            }
            float leading = ufont.GetFontDescriptor(BaseFont.BBOXURY, usize) - ufont.GetFontDescriptor(BaseFont.BBOXLLY, usize);
            int   maxFit  = (int)(h / leading) + 1;
            int   first   = 0;
            int   last    = 0;

            last  = topChoice + maxFit / 2 + 1;
            first = last - maxFit;
            if (first < 0)
            {
                last += first;
                first = 0;
            }
            //        first = topChoice;
            last = first + maxFit;
            if (last > _choices.Length)
            {
                last = _choices.Length;
            }
            TopFirst = first;
            app.SaveState();
            app.Rectangle(offsetX, offsetX, box.Width - 2 * offsetX, box.Height - 2 * offsetX);
            app.Clip();
            app.NewPath();
            BaseColor fcolor = (textColor == null) ? GrayColor.Grayblack : textColor;

            app.SetColorFill(new BaseColor(10, 36, 106));
            app.Rectangle(offsetX, offsetX + h - (topChoice - first + 1) * leading, box.Width - 2 * offsetX, leading);
            app.Fill();
            float xp = offsetX * 2;
            float yp = offsetX + h - ufont.GetFontDescriptor(BaseFont.BBOXURY, usize);

            for (int idx = first; idx < last; ++idx, yp -= leading)
            {
                string ptext = _choices[idx];
                int    rtl   = checkRtl(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
                ptext = RemoveCrlf(ptext);
                Phrase phrase = composePhrase(ptext, ufont, (idx == topChoice) ? GrayColor.Graywhite : fcolor, usize);
                ColumnText.ShowTextAligned(app, Element.ALIGN_LEFT, phrase, xp, yp, 0, rtl, 0);
            }
            app.RestoreState();
            app.EndVariableText();
            return(app);
        }
예제 #23
0
        /// <summary>
        /// Constructs a  PdfChunk -object.
        /// </summary>
        /// <param name="chunk">the original  Chunk -object</param>
        /// <param name="action">the  PdfAction  if the  Chunk  comes from an  Anchor </param>

        internal PdfChunk(Chunk chunk, PdfAction action)
        {
            _thisChunk[0] = this;
            value         = chunk.Content;

            Font  f    = chunk.Font;
            float size = f.Size;

            if (size.ApproxEquals(text.Font.UNDEFINED))
            {
                size = 12;
            }
            BaseFont = f.BaseFont;
            BaseFont bf    = f.BaseFont;
            int      style = f.Style;

            if (style == text.Font.UNDEFINED)
            {
                style = text.Font.NORMAL;
            }
            if (BaseFont == null)
            {
                // translation of the font-family to a PDF font-family
                BaseFont = f.GetCalculatedBaseFont(false);
            }
            else
            {
                // bold simulation
                if ((style & text.Font.BOLD) != 0)
                {
                    Attributes[Chunk.TEXTRENDERMODE] = new object[] { PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, size / 30f, null }
                }
                ;
                // italic simulation
                if ((style & text.Font.ITALIC) != 0)
                {
                    Attributes[Chunk.SKEW] = new[] { 0, ItalicAngle }
                }
                ;
            }
            font = new PdfFont(BaseFont, size);
            // other style possibilities
            Hashtable attr = chunk.Attributes;

            if (attr != null)
            {
                foreach (DictionaryEntry entry in attr)
                {
                    string name = (string)entry.Key;
                    if (_keysAttributes.ContainsKey(name))
                    {
                        Attributes[name] = entry.Value;
                    }
                    else if (_keysNoStroke.ContainsKey(name))
                    {
                        NoStroke[name] = entry.Value;
                    }
                }
                if ("".Equals(attr[Chunk.GENERICTAG]))
                {
                    Attributes[Chunk.GENERICTAG] = chunk.Content;
                }
            }
            if (f.IsUnderlined())
            {
                object[]   obj    = { null, new[] { 0, 1f / 15, 0, -1f / 3, 0 } };
                object[][] unders = Utilities.AddToArray((object[][])Attributes[Chunk.UNDERLINE], obj);
                Attributes[Chunk.UNDERLINE] = unders;
            }
            if (f.IsStrikethru())
            {
                object[]   obj    = { null, new[] { 0, 1f / 15, 0, 1f / 3, 0 } };
                object[][] unders = Utilities.AddToArray((object[][])Attributes[Chunk.UNDERLINE], obj);
                Attributes[Chunk.UNDERLINE] = unders;
            }
            if (action != null)
            {
                Attributes[Chunk.ACTION] = action;
            }
            // the color can't be stored in a PdfFont
            NoStroke[Chunk.COLOR]    = f.Color;
            NoStroke[Chunk.ENCODING] = font.Font.Encoding;
            object[] obj2 = (object[])Attributes[Chunk.IMAGE];
            if (obj2 == null)
            {
                image = null;
            }
            else
            {
                Attributes.Remove(Chunk.HSCALE); // images are scaled in other ways
                image         = (Image)obj2[0];
                OffsetX       = ((float)obj2[1]);
                OffsetY       = ((float)obj2[2]);
                changeLeading = (bool)obj2[3];
            }
            font.Image = image;
            object hs = Attributes[Chunk.HSCALE];

            if (hs != null)
            {
                font.HorizontalScaling = (float)hs;
            }
            encoding       = font.Font.Encoding;
            SplitCharacter = (ISplitCharacter)NoStroke[Chunk.SPLITCHARACTER];
            if (SplitCharacter == null)
            {
                SplitCharacter = DefaultSplitCharacter.Default;
            }
        }
예제 #24
0
        /// <summary>
        /// Write out the columns.  After writing, use
        /// {@link #isOverflow()} to see if all text was written.
        /// @throws DocumentException on error
        /// </summary>
        /// <param name="canvas">PdfContentByte to write with</param>
        /// <param name="document">document to write to (only used to get page limit info)</param>
        /// <param name="documentY">starting y position to begin writing at</param>
        /// <returns>the current height (y position) after writing the columns</returns>
        public float Write(PdfContentByte canvas, PdfDocument document, float documentY)
        {
            _document          = document;
            _columnText.Canvas = canvas;
            if (_columnDefs.Count == 0)
            {
                throw new DocumentException("MultiColumnText has no columns");
            }
            _overflow = false;
            float currentHeight = 0;
            var   done          = false;

            while (!done)
            {
                if (_top.ApproxEquals(AUTOMATIC))
                {
                    _top = document.GetVerticalPosition(true);
                }
                else if (_nextY.ApproxEquals(AUTOMATIC))
                {
                    _nextY = document.GetVerticalPosition(true); // RS - 07/07/2005 - - Get current doc writing position for top of columns on new page.
                }

                var currentDef = (ColumnDef)_columnDefs[CurrentColumn];
                _columnText.YLine = _top;

                var left  = currentDef.ResolvePositions(Rectangle.LEFT_BORDER);
                var right = currentDef.ResolvePositions(Rectangle.RIGHT_BORDER);
                if (document.IsMarginMirroring() && document.PageNumber % 2 == 0)
                {
                    var delta = document.RightMargin - document.Left;
                    left  = (float[])left.Clone();
                    right = (float[])right.Clone();
                    for (var i = 0; i < left.Length; i += 2)
                    {
                        left[i] -= delta;
                    }
                    for (var i = 0; i < right.Length; i += 2)
                    {
                        right[i] -= delta;
                    }
                }
                currentHeight = Math.Max(currentHeight, getHeight(left, right));

                if (currentDef.IsSimple())
                {
                    _columnText.SetSimpleColumn(left[2], left[3], right[0], right[1]);
                }
                else
                {
                    _columnText.SetColumns(left, right);
                }

                var result = _columnText.Go();
                if ((result & ColumnText.NO_MORE_TEXT) != 0)
                {
                    done = true;
                    _top = _columnText.YLine;
                }
                else if (ShiftCurrentColumn())
                {
                    _top = _nextY;
                }
                else
                {  // check if we are done because of height
                    _totalHeight += currentHeight;

                    if ((_desiredHeight.ApproxNotEqual(AUTOMATIC)) && (_totalHeight >= _desiredHeight))
                    {
                        _overflow = true;
                        break;
                    }
                    else
                    {  // need to start new page and reset the columns
                        documentY = _nextY;
                        newPage();
                        currentHeight = 0;
                    }
                }
            }
            if (_desiredHeight.ApproxEquals(AUTOMATIC) && _columnDefs.Count == 1)
            {
                currentHeight = documentY - _columnText.YLine;
            }
            return(currentHeight);
        }
예제 #25
0
        private PdfObject getColorspace()
        {
            if (_iccProfile != null)
            {
                if ((_colorType & 2) == 0)
                {
                    return(PdfName.Devicegray);
                }
                else
                {
                    return(PdfName.Devicergb);
                }
            }
            if (_gamma.ApproxEquals(1f) && !_hasChrm)
            {
                if ((_colorType & 2) == 0)
                {
                    return(PdfName.Devicegray);
                }
                else
                {
                    return(PdfName.Devicergb);
                }
            }
            else
            {
                var array = new PdfArray();
                var dic   = new PdfDictionary();
                if ((_colorType & 2) == 0)
                {
                    if (_gamma.ApproxEquals(1f))
                    {
                        return(PdfName.Devicegray);
                    }

                    array.Add(PdfName.Calgray);
                    dic.Put(PdfName.Gamma, new PdfNumber(_gamma));
                    dic.Put(PdfName.Whitepoint, new PdfLiteral("[1 1 1]"));
                    array.Add(dic);
                }
                else
                {
                    PdfObject wp = new PdfLiteral("[1 1 1]");
                    array.Add(PdfName.Calrgb);
                    if (_gamma.ApproxNotEqual(1f))
                    {
                        var gm = new PdfArray();
                        var n  = new PdfNumber(_gamma);
                        gm.Add(n);
                        gm.Add(n);
                        gm.Add(n);
                        dic.Put(PdfName.Gamma, gm);
                    }
                    if (_hasChrm)
                    {
                        var   z   = _yW * ((_xG - _xB) * _yR - (_xR - _xB) * _yG + (_xR - _xG) * _yB);
                        var   ya  = _yR * ((_xG - _xB) * _yW - (_xW - _xB) * _yG + (_xW - _xG) * _yB) / z;
                        var   xa  = ya * _xR / _yR;
                        var   za  = ya * ((1 - _xR) / _yR - 1);
                        var   yb  = -_yG * ((_xR - _xB) * _yW - (_xW - _xB) * _yR + (_xW - _xR) * _yB) / z;
                        var   xb  = yb * _xG / _yG;
                        var   zb  = yb * ((1 - _xG) / _yG - 1);
                        var   yc  = _yB * ((_xR - _xG) * _yW - (_xW - _xG) * _yW + (_xW - _xR) * _yG) / z;
                        var   xc  = yc * _xB / _yB;
                        var   zc  = yc * ((1 - _xB) / _yB - 1);
                        var   xw  = xa + xb + xc;
                        float yw  = 1;//YA+YB+YC;
                        var   zw  = za + zb + zc;
                        var   wpa = new PdfArray();
                        wpa.Add(new PdfNumber(xw));
                        wpa.Add(new PdfNumber(yw));
                        wpa.Add(new PdfNumber(zw));
                        wp = wpa;
                        var matrix = new PdfArray();
                        matrix.Add(new PdfNumber(xa));
                        matrix.Add(new PdfNumber(ya));
                        matrix.Add(new PdfNumber(za));
                        matrix.Add(new PdfNumber(xb));
                        matrix.Add(new PdfNumber(yb));
                        matrix.Add(new PdfNumber(zb));
                        matrix.Add(new PdfNumber(xc));
                        matrix.Add(new PdfNumber(yc));
                        matrix.Add(new PdfNumber(zc));
                        dic.Put(PdfName.Matrix, matrix);
                    }
                    dic.Put(PdfName.Whitepoint, wp);
                    array.Add(dic);
                }
                return(array);
            }
        }
        /// <summary>
        /// Gets the field appearance.
        /// for a check field
        /// otherwise
        /// @throws IOException on error
        /// @throws DocumentException on error
        /// </summary>
        /// <param name="isRadio"> true  for a radio field and  false </param>
        /// <param name="on"> true  for the checked state,  false </param>
        /// <returns>the appearance</returns>
        public PdfAppearance GetAppearance(bool isRadio, bool on)
        {
            if (isRadio && _checkType == TYPE_CIRCLE)
            {
                return(GetAppearanceRadioCircle(on));
            }
            PdfAppearance app = GetBorderAppearance();

            if (!on)
            {
                return(app);
            }
            BaseFont ufont       = RealFont;
            bool     borderExtra = borderStyle == PdfBorderDictionary.STYLE_BEVELED || borderStyle == PdfBorderDictionary.STYLE_INSET;
            float    h           = box.Height - borderWidth * 2;
            float    bw2         = borderWidth;

            if (borderExtra)
            {
                h   -= borderWidth * 2;
                bw2 *= 2;
            }
            float offsetX = (borderExtra ? 2 * borderWidth : borderWidth);

            offsetX = Math.Max(offsetX, 1);
            float offX  = Math.Min(bw2, offsetX);
            float wt    = box.Width - 2 * offX;
            float ht    = box.Height - 2 * offX;
            float fsize = fontSize;

            if (fsize.ApproxEquals(0))
            {
                float bw = ufont.GetWidthPoint(text, 1);
                if (bw.ApproxEquals(0))
                {
                    fsize = 12;
                }
                else
                {
                    fsize = wt / bw;
                }
                float nfsize = h / (ufont.GetFontDescriptor(BaseFont.ASCENT, 1));
                fsize = Math.Min(fsize, nfsize);
            }
            app.SaveState();
            app.Rectangle(offX, offX, wt, ht);
            app.Clip();
            app.NewPath();
            if (textColor == null)
            {
                app.ResetGrayFill();
            }
            else
            {
                app.SetColorFill(textColor);
            }
            app.BeginText();
            app.SetFontAndSize(ufont, fsize);
            app.SetTextMatrix((box.Width - ufont.GetWidthPoint(text, fsize)) / 2,
                              (box.Height - ufont.GetAscentPoint(text, fsize)) / 2);
            app.ShowText(text);
            app.EndText();
            app.RestoreState();
            return(app);
        }
예제 #27
0
 /// <summary>
 /// Calculates the velocity that the drive should automatically rotate the control with.
 /// </summary>
 /// <returns>The velocity to drive the control automatically with.</returns>
 protected virtual float CalculateAutoDriveVelocity()
 {
     return((Facade.MoveToTargetValue && !currentPseudoRotation.ApproxEquals(ActualTargetAngle, TargetValueReachedThreshold) ? Facade.DriveSpeed : 0f) * CalculateDirectionMultiplier());
 }