Beispiel #1
0
        private static void KeepFonts(HashSet <string> fontsToKeep, Atom atomDA)
        {
            string    da    = Atom.GetText(atomDA);
            ArrayAtom array = ArrayAtom.FromContentStream(ASCIIEncoding.ASCII.GetBytes(da));
            var       items = OpAtom.Find(array, new string[] { "Tf" });

            foreach (var pair in items)
            {
                Atom[] args = OpAtom.GetParameters(array, pair.Item2);
                Debug.Assert(args != null);                 // shouldn't really happen
                if (args != null)
                {
                    fontsToKeep.Add(Atom.GetName(args[0]));
                }
            }
        }
Beispiel #2
0
            public ArrayAtom GetTextOperator()
            {
                Debug.Assert(_text != null);
                // get data and widths
                byte[] section = new byte[_text.StreamLength];
                Array.Copy(_data, _text.StreamOffset, section, 0, _text.StreamLength);
                IDictionary <char, int> widths = _text.Font.Widths;
                // convert to atoms
                ArrayAtom textOp    = ArrayAtom.FromContentStream(section);
                string    srcOp     = ((OpAtom)textOp[1]).Text;
                int       numParams = srcOp == "\"" ? 4 : 2;

                Debug.Assert(textOp.Count == numParams);
                ArrayAtom srcParams = textOp[numParams == 4 ? 2 : 0] as ArrayAtom;

                if (srcParams == null)
                {
                    Debug.Assert(srcOp != "TJ");
                    srcParams = new ArrayAtom();
                    srcParams.Add(textOp[0]);
                }
                ArrayAtom dstParams = new ArrayAtom();
                // copy items
                int textSpanIndex = 0;

                for (int i = 0; i < srcParams.Count; i++)
                {
                    Atom item = srcParams[i];
                    if (item is StringAtom)
                    {
                        StringAtom             str       = (StringAtom)item;
                        Tuple <string, bool[]> redaction = null;
                        _redactions.TryGetValue(textSpanIndex++, out redaction);
                        if (redaction == null)
                        {
                            dstParams.Add(item.Clone());
                        }
                        else
                        {
                            string encoded  = str.Text;
                            string whole    = redaction.Item1;
                            bool[] redacted = redaction.Item2;
                            Debug.Assert((encoded.Length == whole.Length) || (encoded.Length == whole.Length * 2));
                            int bytesPerChar = encoded.Length / whole.Length;
                            int p1           = 0;
                            while (p1 < redacted.Length)
                            {
                                bool hidden       = redacted[p1];
                                int  width1000ths = 0;
                                int  p2;
                                for (p2 = p1; p2 < redacted.Length; p2++)
                                {
                                    if (hidden != redacted[p2])
                                    {
                                        break;
                                    }
                                    if (hidden)
                                    {
                                        width1000ths += widths[whole[p2]];
                                    }
                                }
                                if (hidden)
                                {
                                    dstParams.Add(new NumAtom(-width1000ths));
                                }
                                else
                                {
                                    string sub1 = encoded.Substring(p1 * bytesPerChar, (p2 - p1) * bytesPerChar);
                                    if (sub1.Length > 0)
                                    {
                                        dstParams.Add(new StringAtom(sub1));
                                    }
                                }
                                p1 = p2;
                            }
                        }
                    }
                    else if (item is NumAtom)
                    {
                        NumAtom num = (NumAtom)item;
                        dstParams.Add(item.Clone());
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                // make new operators
                ArrayAtom newTextOp = new ArrayAtom();

                if (srcOp == "\'")
                {
                    newTextOp.Add(new OpAtom("T*"));
                }
                else if (srcOp == "\"")
                {
                    newTextOp.Add(textOp[0].Clone());
                    newTextOp.Add(new OpAtom("Tw"));
                    newTextOp.Add(textOp[1].Clone());
                    newTextOp.Add(new OpAtom("Tc"));
                    newTextOp.Add(new OpAtom("T*"));
                }
                newTextOp.Add(dstParams);
                newTextOp.Add(new OpAtom("TJ"));
                return(newTextOp);
            }