Пример #1
0
        //
        // public methods
        //

        #region public PDFListNumberingStack OpenNumberingStack(string name)

        /// <summary>
        /// Opens an existing stack if the names match, or begins a new stack (setting it as current)
        /// </summary>
        /// <param name="name">The name of the stack to open. If the name is not null or empty</param>
        /// <returns>The appropriate numbering stack.</returns>
        /// <remarks>Named stacks are remembered throughout the lisf of the document, so they can be re-opened at any point.
        /// Un-named stacks will only persist until they are completely colsed.</remarks>
        public PDFListNumberingStack OpenNumberingStack(string name, ListStyle initStyle)
        {
            //if we have a current stack and either both names are empty, or the names match - then this is the one.
            if (_currentStack != null && ((string.IsNullOrEmpty(name) && string.IsNullOrEmpty(_currentStack.Name)) || string.Equals(name, _currentStack.Name)))
            {
                return(_currentStack);
            }

            //otherwise if we do have a name, then lets chack and see if we have a reference.
            else if (_listStacks.Count > 0 && !string.IsNullOrEmpty(name))
            {
                foreach (PDFListNumberingStack stack in _listStacks)
                {
                    if (string.Equals(name, stack.Name))
                    {
                        _currentStack = stack;
                        return(stack);
                    }
                }
            }

            //we don't have an existing stack so if we are not a group then we want to be pushed onto the current stack (if there is one)
            PDFListNumberingStack newStack;

            if (null != _currentStack && string.IsNullOrEmpty(name))
            {
                newStack = _currentStack;
            }
            else //otherwise just create one.
            {
                newStack = new PDFListNumberingStack(name);

                //we only remember named stacks - so we can refer back to them.
                if (!string.IsNullOrEmpty(name))
                {
                    _listStacks.Add(newStack);
                }
            }
            ListNumberingGroupStyle type = initStyle.NumberingStyle;

            //TODO: Add pre, post and concat to style
            string prefix      = initStyle.NumberPrefix;
            string postfix     = initStyle.NumberPostfix;
            bool   concatenate = initStyle.ConcatenateWithParent;

            newStack.Push(type, prefix, postfix, concatenate);

            _currentStack = newStack;
            return(_currentStack);
        }
Пример #2
0
        /// <summary>
        /// Closes the current stack, so it is no longer current.
        /// It is still retained in the list, so can be joined again, if the name of the stack is not empty.
        /// </summary>
        public void CloseNumberingStack()
        {
            if (null == _currentStack)
            {
                throw new NullReferenceException("Current numbering stack is empty");
            }

            //We pop the last one if there is more than one current list stack
            if (_currentStack.Count > 1)
            {
                _currentStack.Pop();
            }
            else
            {
                _currentStack = null;
            }
        }